CS FundamentalsVery hardGATE CS

A condition-variable based bounded buffer uses a single condition variable `cv` for both 'not full' and 'not empty', and signals with `signal(cv)` (wake one). With several producers and consumers, what can go wrong?

  1. A. Mutual exclusion is violated
  2. B. Items are delivered out of order
  3. C. Nothing; one condition variable is always enough
  4. D. A signal can wake the wrong kind of thread (e.g. a producer wakes another producer), leaving a consumer asleep even though data is available, and all threads may end up waiting

Correct answer: D. A signal can wake the wrong kind of thread (e.g. a producer wakes another producer), leaving a consumer asleep even though data is available, and all threads may end up waiting

With one shared condition, signal() may wake a thread whose condition is still false; it goes back to sleep and the needed wakeup is lost. Use two condition variables or broadcast.

More Operating Systems questions

Exams that ask this topic