Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,

Similar presentations


Presentation on theme: "Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,"— Presentation transcript:

1 Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly, it all falls apart.  Still doesn’t guard against starvation of writers. How to modify to guard against writer starvation?

2 Chapter 72 Monitor Implementation (using semaphores)  Need mutual exclusion semaphore mutex (init to 1) so that only one process is active within monitor  Need a semaphore next (next to exit) for the signaling process to suspend itself initialized to zero  next_count is number of processes blocked on next  Before exiting a procedure, process must either: Signal other waiting processes in monitor (next) before exiting, or Signal mutex and exit

3 Chapter 73 Monitor Implementation The monitor “compiler” has to automatically insert this code into compiled procedures: Procedure F: wait(mutex);... body of F... if (next_count>0) signal(next); else signal(mutex); end;

4 Chapter 74 Condition Variable Implementation (**with correction of signal**) x.wait() { x.count++; if (next_count>0) signal(next); else signal(mutex); wait(x.sem); x.count--; } x.signal() { if (x.count >0){ next_count++; signal(x.sem); wait(next); next_count--; } Each condition has a count, and a standard semaphore (with associated queue) initialized to 0


Download ppt "Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,"

Similar presentations


Ads by Google