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?
- A. Because wait() may return only after the monitor is destroyed
- B. Because Mesa monitors do not provide mutual exclusion
- C. Because signal() under Mesa semantics wakes all waiters at once
- 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
- Five dining philosophers each pick up the left fork and then the right fork. Which change removes the possibility of deadlock without a…
- A user creates file f, makes a hard link h to it and a symbolic link s to f. Then f is deleted and a NEW file named f is created with…
- In the standard five-state process model (new, ready, running, blocked, exit), which transition can NOT happen directly?
- A program uses user-level threads mapped many-to-one onto a single kernel thread. One thread calls a blocking read() on a slow device…
- A bounded-buffer producer is written as wait(mutex); wait(empty); add item; signal(mutex); signal(full); while the consumer is the usual…
- Which statement about Belady's anomaly is correct?