1 / 6

Readers/Writers Problem

Readers/Writers Problem. Multiple processes wanting to read an item, and one or more needing to write (Think of airline reservations…) Rather than enforce mutual exclusion on every access, use these rules: Any number of readers can read simultaneously Only one writer at a time!

marshal
Download Presentation

Readers/Writers Problem

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. Readers/Writers Problem • Multiple processes wanting to read an item, and one or more needing to write • (Think of airline reservations…) • Rather than enforce mutual exclusion on every access, use these rules: • Any number of readers can read simultaneously • Only one writer at a time! • No readers if a writer is writing

  2. Readers/Writers Problem • “First readers/writers” problem (reader priority): • No reader will wait (for other readers to finish) even if a writer is waiting • Writer starvation possible • Semaphore solution • “Second reader/writers” problem (writer priority): • No new readers allowed once a writer has asked for access • This solution will be discussed with monitors.

  3. First Readers/Writers Problem Priority to readers (writer starvation possible)

  4. Notes: First Readers/Writers Solution • Semaphore “X” used only to protect the updating of readcount • First reader in must use wsem semaphore for mutual exclusion with the writer(s) • And last one out must signal wsem (indicates no more readers…) • But if another reader arrives too fast, the writer might get locked out again…

  5. Conclusions on Semaphores • Semaphores provide a structured tool for enforcing mutual exclusion and coordinating processes. • Avoid busy wait, but not completely. • If used correctly, avoid deadlock and starvation. • But tricky to use • if wait(S) and signal(S) are scattered among several processes it may be difficult to use them correctly • One bad process (unmatched wait, etc.) can fail the entire collection of processes, cause deadlock, starvation.

  6. Up next… • Wednesday: • mid-term • Back in auditorim • Friday: • For Assignment #3 (out on Friday) - interprocess communication (4.5, 4.6) • Monday: • Finishing up concurrency with monitors (7.7) • Wednesday • Deadlock (Ch. 8)

More Related