GATEverse
← GATE CSE 2000

Q20

NATMarks unknown

a. Fill in the boxes below to get a solution for the reader-writer problem, using a single binary semaphore, mutex (initialized to 11) and busy waiting. Write the box numbers (11, 22 and 33), and their contents in your answer book. int R = 0, W = 0; Reader () { L1: wait (mutex); if (W == 0) { R = R + 1; ▭ ______________(1) } else { ▭ ______________(2) goto L1; } ..../* do the read*/ wait (mutex); R = R - 1; signal (mutex); } Writer () { L2: wait (mutex); if (▭) { _________ (3) signal (mutex); goto L2; } W=1; signal (mutex); ...../*do the write*/ wait( mutex); W=0; signal (mutex); } b. Can the above solution lead to starvation of writers?

Sign in to save attempts.

Loading…