0% found this document useful (0 votes)
25 views6 pages

Multiple Processes Wanting To Read An Item, and One or More Needing To Write - Ather Than Enforce Mutual Exclusion On Every Access, Use These Rules

The Readers/Writers Problem involves multiple processes that need to either read or write shared data. It allows any number of readers to access the data simultaneously, but only allows one writer at a time. There are two common solutions - the first prioritizes readers and may cause writer starvation, using semaphores. The second prioritizes writers and prevents new readers when a writer is waiting, using monitors. Semaphores provide a way to enforce mutual exclusion and coordinate processes but must be used carefully to avoid issues like deadlock or starvation if not implemented correctly.

Uploaded by

Bharavi K S
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Multiple Processes Wanting To Read An Item, and One or More Needing To Write - Ather Than Enforce Mutual Exclusion On Every Access, Use These Rules

The Readers/Writers Problem involves multiple processes that need to either read or write shared data. It allows any number of readers to access the data simultaneously, but only allows one writer at a time. There are two common solutions - the first prioritizes readers and may cause writer starvation, using semaphores. The second prioritizes writers and prevents new readers when a writer is waiting, using monitors. Semaphores provide a way to enforce mutual exclusion and coordinate processes but must be used carefully to avoid issues like deadlock or starvation if not implemented correctly.

Uploaded by

Bharavi K S
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

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.

First Readers/Writers Problem

Priority to readers (writer starvation possible)

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

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.

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)

You might also like