CS FundamentalsModerateGATE CS

Why must a Mesa-style condition wait be written as `while (!cond) wait(c);` rather than `if (!cond) wait(c);`?

  1. A. Because wait() can return only after a timeout
  2. B. Because after being signalled the waiter does not run immediately, and the condition may be false again when it reacquires the lock
  3. C. Because if() cannot call wait() inside a monitor
  4. D. Because signal() always wakes every waiter

Correct answer: B. Because after being signalled the waiter does not run immediately, and the condition may be false again when it reacquires the lock

Under signal-and-continue, another thread can run between the signal and the waiter regaining the lock and invalidate the condition; spurious wakeups are also allowed. Re-checking in a loop is the safe pattern.

More Operating Systems questions

Exams that ask this topic