CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

A bounded buffer uses semaphores empty = N, full = 0 and mutex = 1. The producer is changed to do wait(mutex) BEFORE wait(empty); the consumer still does wait(full) then wait(mutex). What can happen?

  1. A. Two producers can enter the buffer together, so an item in a slot gets overwritten
  2. B. A consumer can remove an item from an empty buffer and so read a stale slot value
  3. C. With a full buffer the producer sleeps on empty holding mutex, and the consumer blocks on mutex: deadlock
  4. D. Nothing changes in behaviour, since every wait() is still matched by a signal()

Correct answer: C. With a full buffer the producer sleeps on empty holding mutex, and the consumer blocks on mutex: deadlock

With a full buffer the producer takes mutex and sleeps on empty, still holding mutex. The consumer passes wait(full) but then waits for mutex forever, so nobody can signal empty. Counting semaphores must be acquired before the mutex.

More Operating Systems questions

Exams that ask this topic