CS FundamentalsHardGATE CS · Product-company placement

In a monitor with Mesa (signal-and-continue) semantics, why must a consumer check its condition with while (count == 0) wait(notEmpty); rather than if?

  1. A. Because wait() may return only after the monitor is destroyed
  2. B. Because Mesa monitors do not provide mutual exclusion
  3. C. Because signal() under Mesa semantics wakes all waiters at once
  4. D. Because between the signal and the moment the woken thread re-enters, another thread may take the item, so the condition must be re-checked

Correct answer: D. Because between the signal and the moment the woken thread re-enters, another thread may take the item, so the condition must be re-checked

Under Mesa semantics the signaller keeps running and the woken thread only becomes runnable, so the condition may be false again by the time it runs (and spurious wake-ups are allowed). Hoare semantics hands over the monitor immediately, which is when if would suffice.

More Operating Systems questions

Exams that ask this topic