Question: 8 3. a) Remember this readers-writers synchronization problem from BUX and the reference [8] book. do { wait (mutex); read_count++; if (read_count == 1) wait

 8 3. a) Remember this readers-writers synchronization problem from BUX andthe reference [8] book. do { wait (mutex); read_count++; if (read_count ==

8 3. a) Remember this readers-writers synchronization problem from BUX and the reference [8] book. do { wait (mutex); read_count++; if (read_count == 1) wait (rw_mutex); signal (mutex); 1* reading is performed */ do { wait (rw_mutex); wait(mutex); read_count--; /* writing is performed */ if (read_count == 0) signal(rw_mutex); signal(rw_mutex); signal(mutex); } while (true); } while (true); Figure 5.11 The structure of a writer process. Figure 5.12 The structure of a reader process. This solution solves the critical section problem. However, there is a starvation issue here for the writer process. If there is a steady stream of reader processes in the ready queue, the writer process may starve and may not be able to write. We hope you can solve this starvation issue by applying one restriction in the code. The restriction is that if the writer was waiting for a reader, then that reader cannot read again before the writer completes writing. If more than one reader were reading when the writer was waiting, this restriction applies to all those readers. Update the reader and writer code to implement this restriction. HINTS: You do not need any additional mutex for this but need to use both mutexes in both programs. You need a flag variable shared among the writer and readers to indicate if the writer is waiting. Call it the writer_waiting flag. You need a private variable in the reader process, call it i_kept_writer_waiting, so that a reader can remember when starting its next iteration that the writer was waiting when it was reading in the previous iteration

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!