1 / 4

Monitor for Reader/Writers

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?.

cmarianne
Download Presentation

Monitor for Reader/Writers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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? Chapter 7

  2. 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 Monitor Implementation (using semaphores) Chapter 7

  3. 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; Chapter 7

  4. 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--; } } Condition Variable Implementation (**with correction of signal**) Each condition has a count, and a standard semaphore (with associated queue) initialized to 0 Chapter 7

More Related