CS FundamentalsHardGATE CS

A bounded-buffer monitor with Mesa-style signalling uses: get() { if (count == 0) wait(notEmpty); item = buf[out]; count--; ... } and put() calls signal(notEmpty) after storing an item. Two consumers and one producer share it. Which statement is correct?

  1. A. The code is safe because signal always wakes exactly one waiter immediately
  2. B. Underflow is possible because a woken consumer may run after another consumer has taken the item; the wait must sit in a while loop
  3. C. Underflow is impossible, but two consumers may deadlock
  4. D. Replacing signal with broadcast alone makes the code safe

Correct answer: B. Underflow is possible because a woken consumer may run after another consumer has taken the item; the wait must sit in a while loop

In Mesa semantics the signalled thread is only made ready; before it runs, another consumer entering get() can take the item, leaving count == 0. The woken thread then decrements below zero. Rechecking the condition in a while loop fixes it, while broadcast with an if still fails.

More Operating Systems questions

Exams that ask this topic