![]() ![]() Readers can't be both active and waiting unless a writer.nw_active > 0 & nw_waiting > 0 -> nr_waiting > 0.nr_active > 0 & nr_waiting > 0 -> nw_waiting > 0.Safety conditions: Readers and writers can not be active at.Will let all waiting readers into the room. Room as well as readers on the bench, then the last writer to exit ![]() If you a writer waiting to enter, and there are writers in the You will be polite and allow the reader to have The bench to go in, you will sit on a bench. There are writers in the room, but there are readers sitting on If there are readers in the room, you sit on the bench. Suppose you are a writer, and are coming in. You haveĪ room, maybe it has windows so you can look inside. Here is an intuition of how the algorithm behaves. lock isĪ mutex semaphore used by both readers and writers.ġ P( lock ) // lock is a mutex and is initializes to 1.ĥ V( r_sem ) // Allow ourself to get throughġ0 P( r_sem ) // Readers will wait here, if they must wait.ġ6 if (( nr_active = 0 ) & ( nw_waiting > 0 )) // If we are the last readerġ8 while ( nw_waiting > 0 ) // Allow all waiting writers to enterĢ2 w_waiting- // one less waiting writer. R_sem is the semaphore that waiting readers sleep Number of readers waiting to go into the critical section. (readers in critical section, r_waiting is the AsĪ reminder, r_active is the number of active readers You wantĪ deadlock free, starvation free solution.īelow is code for the reader processes. Readers and writers be allowed in at the same time. You want to have a "critical section" where multiple writersĪre allowed, as well as multiple readers, but at no time should 412-Readers/Writers Readers/Writers Problem
0 Comments
Leave a Reply. |