CS FundamentalsVery hardGATE CS

Readers–writers with readers' preference: semaphores mutex = 1 (protects readcount), wrt = 1. Reader: wait(mutex); readcount++; if (readcount == 1) wait(wrt); signal(mutex); read; wait(mutex); readcount--; if (readcount == 0) signal(wrt); signal(mutex). If a writer is writing, 3 readers arrive one after another. Where do they wait?

  1. A. All three wait on wrt
  2. B. All three wait on mutex
  3. C. The first two wait on wrt, the third on mutex
  4. D. The first reader waits on wrt; the other two wait on mutex

Correct answer: D. The first reader waits on wrt; the other two wait on mutex

The first reader holds mutex while it blocks on wrt (readcount == 1), so the next readers cannot even get mutex to increment readcount; they queue on mutex.

More Operating Systems questions

Exams that ask this topic