Brett Shwom
Homework 3

Thread Synchronization:

The gcd thread, before requesting a modulus computation for a pair of numbers to be executed by the worker thread, locks the mutex variable mv. This blocks other threads that wish to request modulus computation from executing. The pair of numbers to be processed are then put into a globally avaibalbe struct. Then, a signal (pthread_cond_signal()) is sent to the worker thread (the worker thread is waiting for condition wake_thread). The worker thread, after locking a variable main_mv, then takes the pair of numbers stored in the global variable and computes the corresponding modulus value and places that in another global variable. The main thread then realeases its lock on main_mv for which the gcd thread is requesting a lock. The gcd thread then takes the result from the global variable and releases its lock on main_mv.

Timings:

It seems that the program execution slows down greatly when there are a larger number of threads. I.e. X modulus computations would take less time if there were only 2 threads in the program, and more time if there were say 12.