CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

In a monitor with Mesa (signal-and-continue) semantics, why must a consumer write `while (count == 0) wait(notEmpty);` instead of `if (count == 0) wait(notEmpty);`?

  1. A. Because wait() can return early when the monitor lock is held by a producer
  2. B. Because Mesa monitors allow only one condition variable per monitor
  3. C. Because the woken thread runs later, and another consumer may have taken the item by then
  4. D. Because a signal sent before the wait is remembered and delivered twice

Correct answer: C. Because the woken thread runs later, and another consumer may have taken the item by then

Under Mesa semantics signal only moves the waiter to the ready queue; the signaller keeps the lock, and other threads may enter and consume the item before the waiter runs. With Hoare semantics the waiter runs immediately, and if would be safe.

More Operating Systems questions

Exams that ask this topic