This assignment will familiarize you with the process synchronization primitives Semaphore, Lock, and Condition. You will be using these primitives to solve two classic synchronization problems: Bounded Buffer, and Readers/Writers. Upon completion you should be more comfortable creating robust multithreaded applications that use shared variables.
Read two popular synchronization problems: Bounder buffer and reader-writer problems.
The bounded-buffer problem (or, produce consumer problem) is a classic example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer.
The solution for the producer is to either go to sleep or discard data if the buffer is full. The next time the consumer removes an item from the buffer, it notifies the producer, who starts to fill the buffer again. In the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means of inter-process communication, typically using semaphores. An inadequate solution could result in a deadlock where both processes are waiting to be awakened. The problem can also be generalized to have multiple producers and consumers.
The readers-writers problem is an example of a common computing problem in concurrency. The problem deals with situations in which many threads must access the same shared memory at one time, some reading and some writing, with the natural constraint that no process may access the share for reading or writing while another process is in the act of writing to it. (In particular, it is allowed for two or more readers to access the share at the same time.) A readers-writer lock is a data structure that solves one or more of the readers-writers problems. The solution of the text book and slides gives waiting readers priority over waiting writers. For example, if a writer is waiting for access to the database and a reader is currently reading, another reader can come and start reading without waiting at all. The writer must wait for all readers that arrive and start executing to finish reading before it can start writing. For this MP, we will be changing the priority. We want updates to the database to have priority. So, if there is a writer waiting to write, any readers that arrive must wait for all writers that are waiting to write as well as any writers that arrive in the meantime. As long as there is a reader reading and no writer is waiting, or new reader arrives while another reader is reading, readers get to read the data. But when a reader arrives, and if there is at least one writer waiting to write, all the writers that follow (while the reader is waiting) should go through before the reader.
A good idea would be to implement the algorithm in the book, get it working, and then to update it accordingly to implement the writer priority. Not only will this be easier, but it will help you to understand what the assignment is asking you to do.