5 questions to test your understanding
In a bounded buffer monitor using Mesa semantics, a consumer thread wakes from wait(notEmpty) and executes: 'if (buffer.isEmpty()) { wait(notEmpty); } consume();'. What is the danger?
When a thread calls wait(cond) inside a monitor, what two things happen atomically?
In Hoare-style monitors, a call to signal() causes the signaling thread to immediately yield the monitor to the woken thread, guaranteeing the condition still holds when the waiter resumes.
A monitor automatically ensures that only one thread executes inside it at any time, without the programmer needing to write explicit lock-acquire and lock-release calls.
Why must waiting on a condition variable always use a while loop (not an if statement) in Mesa-style monitors? Describe the specific scenario where an if statement would cause a bug.