Questions: Monitors and Condition Variables

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

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?

ANo danger — signal() in Mesa semantics guarantees the condition holds when the woken thread resumes
BThe thread may consume from an empty buffer, because another thread could have consumed the item before this thread reacquired the monitor lock
CThe thread will deadlock, because calling wait() inside an if-statement is not allowed
DThe signal will be lost, because Mesa monitors use broadcast() instead of signal()
Question 2 Multiple Choice

When a thread calls wait(cond) inside a monitor, what two things happen atomically?

AThe thread acquires the monitor lock and enters the critical section
BThe thread releases the monitor lock and suspends itself
CThe thread signals another thread and then blocks waiting for a response
DThe thread increments a semaphore and yields the CPU
Question 3 True / False

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.

TTrue
FFalse
Question 4 True / False

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.

TTrue
FFalse
Question 5 Short Answer

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.

Think about your answer, then reveal below.