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);`?
- A. Because wait() can return early when the monitor lock is held by a producer
- B. Because Mesa monitors allow only one condition variable per monitor
- C. Because the woken thread runs later, and another consumer may have taken the item by then
- 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
- In the first readers-writers solution (readers share a count; the first reader locks out writers and the last reader lets them in), what…
- Five philosophers each pick up their left fork and then their right fork. Which change removes the possibility of deadlock without adding…
- Two processes use while (lock) ; lock = 1; / CS / lock = 0; with a plain shared variable (no atomic instruction). Which requirement of the…
- In Peterson's algorithm for P0 and P1, the entry code for Pi is flag[i] = true; turn = j; while (flag[j] && turn == j);. What goes wrong…
- A counting semaphore is implemented WITHOUT busy waiting, and its value is −3 at some moment. What does this tell you?
- Which statement about user-level threads in a many-to-one model is correct?