Assignment 3

Due Date: Monday Oct 26

1. Implement recursive mutex locks using ordinary mutexes and condition variable. Recall that if a thread attempts to lock an ordinary mutex it is already holding, then it will self-block. In contrast, a recursive mutex may be acquired any number of times by a single thread. The thread must unlock the mutex the same number of times that it locks it before another thread may acquire the lock.

2. Implement reader/writer locks using mutexes and condition variables. Recall the following properties of reader/writer locks:

a. They may be locked for reading or locked for writing.

b. Any number of threads may acquire the lock for reading, as long as no thread has acquired it for writing.

c. At most one thread may acquire the lock for writing as long as no threads ar holding it for reading.

d. If a thread is blocked trying to acquire the lock for writing, then future attempts to acquire the lock for reading will block until there are no threads holding the lock for writing or waiting to acquire it for writing.

3. Implement barrier synchronization as described in class. This should consist of a type, barrier_t, and two functions, barrier_init and barrier_wait. The barrier_init call is used to initialize the structure and set the barrier size N. The barrier_wait function blocks the calling thread until it is called by a total of N threads. Upon the N-th call, all threads are unblocked and the barrier reset.