CS FundamentalsHardGATE CS

A bounded-buffer producer is written as wait(mutex); wait(empty); add item; signal(mutex); signal(full); while the consumer is the usual wait(full); wait(mutex); remove; signal(mutex); signal(empty). What can go wrong?

  1. A. Two producers may write the same slot
  2. B. Nothing; the order of wait calls does not matter
  3. C. The consumer may remove from an empty buffer
  4. D. When the buffer is full, the producer sleeps on empty while holding mutex, and the consumer blocks on mutex: deadlock

Correct answer: D. When the buffer is full, the producer sleeps on empty while holding mutex, and the consumer blocks on mutex: deadlock

wait(empty) blocks only when the buffer is full, and the producer then holds mutex while sleeping. The consumer that would free a slot needs mutex first, so neither can proceed. Counting waits must come before taking the mutex.

More Operating Systems questions

Exams that ask this topic