📝 Resuming Processes within a Monitor in Process synchronization (36 MCQs)
Resuming Condition-Waiting Processes Inside a Monitor
Resuming processes within a monitor concerns how a waiting process regains access after another process signals its condition variable. Monitor implementations must define whether signalling transfers control immediately or merely makes the waiter eligible to resume later. These rules determine monitor occupancy, condition rechecking, and the ordering of operations between the signalling process and the awakened process.
Why Signal and Resume Semantics Affect Correctness
When a process waits on a condition variable, it temporarily releases monitor access so another process can enter and change the protected state. Once the condition is signalled, the waiting process must resume according to the monitor's scheduling semantics. If the signalling and resuming process overlap incorrectly, shared-state assumptions may become invalid.
Hoare and Mesa Monitor Signalling Behaviour
In Hoare-style semantics, signal immediately transfers monitor control to a waiting process, while the signaller temporarily waits. In Mesa-style semantics, signal makes a waiter eligible to resume later, and the signaller continues until leaving the monitor. Under Mesa semantics, wait conditions must generally be checked again in a loop.
Two Processes Competing After a Condition Signal
Suppose P1 waits because a buffer is empty and P2 later inserts an item and signals the condition. Under Hoare semantics, P1 immediately receives monitor control. Under Mesa semantics, P2 continues and may leave the monitor before P1 resumes. Another process might consume the item first, so P1 must recheck buffer availability.
Scheduling Behaviour and Condition-Variable Reliability
Clear resumption rules allow monitors to coordinate producers, consumers, and resource managers correctly. Hoare semantics simplify reasoning about the condition immediately after signalling but require direct handoff. Mesa semantics fit common scheduling systems but require condition loops because awakened processes may find the condition changed. Neither model independently guarantees starvation freedom.
Misconceptions About Resuming Monitor Waiters
'A signalled process always runs immediately' is incorrect under Mesa semantics because it becomes eligible rather than guaranteed to execute. 'A Mesa waiter can safely assume its condition remains true' is incorrect because other processes may change shared state first. 'Hoare signalling lets both processes occupy the monitor simultaneously' is incorrect because control is transferred.
Exam Focus: Comparing Monitor Resumption Semantics
Trace signal operations under Hoare and Mesa semantics and identify which process retains monitor execution. Explain signal-and-wait and signal-and-continue behaviour. Questions may examine condition loops, monitor handoff, competition after wake-up, and why a process must verify its condition before using a shared resource.
Key Terms of Monitor Resumption
- Hoare semantics - Signalling transfers control immediately.
- Mesa semantics - Signalling makes waiters eligible.
- Handoff - Immediate transfer of monitor control.
- Signaller - Process issuing condition notification.
- Waiter - Process suspended on a condition.
- Condition loop - Rechecks a condition after waking.
📝 All Resuming Processes within a Monitor in Process synchronization MCQs
Q1. Which execution rule defines Hoare-style signal-and-wait semantics?
📖 Explanation: Hoare semantics perform an immediate handoff. The awakened process runs while the signaler waits in the urgent queue, so only one process remains active inside the monitor at any moment.
Q2. Under Mesa-style signal-and-continue semantics, what happens immediately after a process signals a condition?
📖 Explanation: Mesa semantics do not transfer monitor ownership at the signal operation. The signaling process continues, and the awakened thread must later compete to reacquire the monitor before checking shared state.
Q3. In a Hoare-style monitor, what is the purpose of the urgent queue?
📖 Explanation: The urgent queue preserves the signaler while the selected waiter runs. When that waiter leaves the monitor or waits again, the suspended signaler can resume without competing as a new entrant.
Q4. A process calls signal on a condition variable when no process is waiting there. What normally happens?
📖 Explanation: A condition variable is a waiting queue rather than a counter. With no waiter present, signal has no lasting effect, so correctness must depend on checking the protected state predicate.
Q5. What does broadcast do to processes waiting on one monitor condition variable?
📖 Explanation: Broadcast notifies every process currently waiting on that condition. The monitor still admits only one active process at a time, so awakened threads reacquire access separately and recheck their predicates.
Q6. Why must a Mesa-style waiter normally test its predicate again after waking?
📖 Explanation: A Mesa notification only makes a waiter eligible; it does not reserve the condition. A competing thread can consume the resource or alter the state before the original waiter resumes.
Q7. Why can a waiter in a classical Hoare monitor often use a single condition test before waiting?
📖 Explanation: Immediate handoff suspends the signaler and gives the waiter control before another entrant can change the protected state. This is why the condition is considered valid at that handoff point.
Q8. Why must a condition wait release monitor ownership while the process is blocked?
📖 Explanation: A waiter that retains monitor ownership could prevent every other process from making the awaited condition true. The wait operation therefore suspends the caller and releases exclusive monitor access during the entire wait interval.
Q9. Under Mesa semantics, what does a successful signal promise to a waiting process?
📖 Explanation: Mesa signaling is a notification rather than a resource reservation or immediate transfer. The waiter may resume after other monitor activity, so it must verify the relevant predicate while holding the lock.
Q10. Which statement best distinguishes a condition-variable queue from a Hoare urgent queue?
📖 Explanation: Condition queues hold processes blocked until a monitored predicate may change. A Hoare urgent queue instead holds a signaler suspended during the immediate handoff, until the awakened waiter relinquishes monitor control.
Q11. A team compares signal-and-wait with signal-and-continue and observes fewer immediate handoffs in the latter. What conclusion is justified?
📖 Explanation: Immediate handoff can simplify reasoning but adds control transfers. Continuing after signaling can reduce handoffs yet cause later predicate checks and contention, so workload measurements are needed before choosing for that application.
Q12. Does choosing Hoare or Mesa semantics by itself guarantee that every waiting process eventually resumes?
📖 Explanation: The signaling discipline defines control transfer, not a complete fairness policy. Starvation freedom also requires suitable queue selection and scheduling assumptions, which neither Hoare nor Mesa semantics automatically provide in the implementation.
Q13. What should a signaler do before signaling a Hoare-style condition if the awakened process relies on a shared-state predicate?
📖 Explanation: The awakened process runs immediately and reasons from the state established by the signaler. Updating the predicate before signaling gives the waiter the condition that justified the handoff at the moment of resumption.
Q14. Why are while loops recommended around condition waits in systems that permit spurious wakeups?
📖 Explanation: Some condition-wait implementations permit a thread to return without a matching signal. Rechecking the predicate in a loop prevents the thread from proceeding merely because the wait call returned under the monitor lock.
Q15. Process A signals process B on a condition in a Hoare monitor. Which process executes monitor code immediately after the signal?
📖 Explanation: Hoare signal-and-wait semantics transfer exclusive monitor control to the selected waiter immediately. The signaler is suspended in the urgent queue and resumes after the waiter leaves or blocks to preserve exclusive access.
Q16. A Mesa monitor's process P signals waiting process Q. What can P do before Q next executes monitor code?
📖 Explanation: Signal-and-continue leaves ownership with P. Q becomes eligible but cannot execute protected code until the monitor is available and it successfully reacquires exclusive access to the monitor while excluding other entrants.
Q17. A buffer has one item and two consumers are waiting under Mesa semantics. One consumer is signaled, but another consumer enters first and removes the item. What should the signaled consumer do?
📖 Explanation: The notification does not reserve the item for the selected consumer. After reacquiring the monitor, that consumer must test the count again and block if the competing consumer emptied the buffer.
Q18. A process wakes from condition c, but its operation also requires predicate d. Predicate d is still false. What is the correct action?
📖 Explanation: A notification concerns the condition associated with that wait, not every prerequisite for an operation. The process must test each required predicate under monitor protection and wait on the appropriate condition.
Q19. Eight consumers wait for a nonempty buffer. A producer inserts one item and broadcasts. Assuming no later insertion, how many consumers can successfully remove an item?
📖 Explanation: Broadcast changes waiter eligibility, not resource quantity. With one item, only one consumer can remove it; later entrants observe an empty buffer and must return to the condition wait under the monitor lock.
Q20. Three processes wait on the same condition variable. A signal operation is issued once. What is the normal effect?
📖 Explanation: A single signal normally makes one waiter eligible, not every process on the condition queue. The other waiters remain blocked until another signal or broadcast makes them eligible on that condition variable.
Q21. A timed condition wait expires and returns with the monitor lock reacquired. The operation should be abandoned if its predicate remains false. What should the process do?
📖 Explanation: Expiration reports that the waiting interval ended, not that the requested state occurred. With the monitor lock reacquired, the process can safely inspect the predicate and apply its timeout policy.
Q22. A programmer checks a predicate, releases the monitor lock, and only afterward registers the process on the condition queue. A signal can occur between those steps. What defect can result?
📖 Explanation: The gap between releasing ownership and joining the wait queue permits a lost wakeup. A correct wait operation atomically releases the lock and blocks so the signaler cannot slip through that interval.
Q23. A monitor implementation returns from wait before the caller has reacquired exclusive monitor ownership. Which diagnosis is correct?
📖 Explanation: The monitor protects shared data through exclusive ownership. A wait operation must reacquire that ownership before returning to protected code; otherwise another process may execute concurrently and create a race.
Q24. A monitor uses this pattern under Mesa semantics: if count equals zero, wait; then remove an item. What is the essential correction?
📖 Explanation: The if statement checks the predicate only before sleeping. Under Mesa scheduling or a spurious wakeup, the state may still be unsuitable when the process resumes, so a while loop is required.
Q25. A developer assumes a signal sent before any process waits will release the next process that later calls wait. What is wrong with this assumption?
📖 Explanation: A condition variable does not accumulate notifications. If no process is waiting at signal time, the event leaves no permit for a later caller, which must rely on synchronized state testing.
Q26. A monitor broadcasts to six waiters, and the implementation allows all six to execute protected statements simultaneously. Which invariant has been broken?
📖 Explanation: Broadcast makes waiters eligible; it does not grant simultaneous ownership. The monitor must serialize their re-entry one at a time after reacquiring the monitor so shared data remains protected by its mutual-exclusion guarantee.
Q27. Trace a Hoare monitor: at t0, A owns the monitor, B waits on x, and C waits to enter. At t1 A signals x; at t2 B runs; at t3 B waits on y. Who owns the monitor immediately after t3?
📖 Explanation: A was suspended by the immediate handoff and placed on the urgent queue. When B waits on y, A can resume; the ordinary entrant C remains outside while the urgent signaler is pending.
Q28. Trace a Mesa buffer: t0 C1 waits with count 0; t1 producer sets count to 1 and signals C1; t2 producer continues; t3 C2 enters and removes the item; t4 C1 reacquires the monitor. What should C1 do?
📖 Explanation: The timeline shows that C2 changes the predicate before C1 resumes. Mesa signaling provides no reservation, so C1 must test the count after reacquiring the lock and wait again before attempting removal.
Q29. Trace a broadcast: C1, C2, and C3 wait for items; a producer inserts two items and broadcasts; C2 removes one, then C3 removes the second; C1 enters last. What is C1's correct next step?
📖 Explanation: Broadcast awakens all three consumers, but the two available items are consumed before C1 enters. C1 must verify the current count under the lock and block while the buffer is empty.
Q30. A performance plot lists competing entrants and waiter-resumption delay in scheduling quanta: (0,1), (1,2), (2,3), (3,4), (4,5). What trend does the data show?
📖 Explanation: Each successive data pair increases both the number of competitors and the measured delay by one. This sample therefore shows a positive relationship between monitor-entry contention and waiter-resumption delay in the recorded runs.
Q31. A timed wait returns a timeout status, but after the process reacquires the monitor lock it finds the required predicate true. What should it do?
📖 Explanation: A timeout result describes the wait interval, not necessarily the state at the instant the lock is reacquired. The process should use the protected predicate to decide whether continuing is safe.
Q32. A monitor broadcasts after two resource units become available to four waiting processes. Under Mesa semantics, which statement is correct?
📖 Explanation: Broadcast affects eligibility, not the number of available units. Processes enter serially, consume resources if the predicate allows, and any process finding no unit remaining must wait again while holding the monitor lock.
Q33. A producer sets ready to true while holding the monitor, calls signal when no waiter exists, and then exits. A consumer enters later. What should the consumer do?
📖 Explanation: The notification itself is not remembered, but the shared ready state remains protected and observable. A later consumer checks that predicate and can proceed when it already holds rather than waiting for a past notification.
Q34. A monitor has separate conditions for buffer-not-empty and system-shutdown. A state change sets only shutdown to true. Which notification is most appropriate?
📖 Explanation: Distinct condition variables represent different predicates. Updating shutdown under monitor protection and notifying its own wait queue targets relevant waiters without needlessly waking consumers whose own buffer predicate remains false.
Q35. In a Mesa monitor, P signals Q and then waits on a different condition before leaving the procedure. When can Q next compete to resume?
📖 Explanation: Mesa signaling makes Q eligible but does not transfer ownership immediately. When P later waits, it releases the monitor, allowing Q to compete for re-entry even though P has not exited its procedure.
Q36. Three Mesa consumers wait for a nonempty buffer. A producer inserts two items and broadcasts. C2 and C3 each acquire the monitor first and remove one item before C1 resumes. What is the final safe action for C1?
📖 Explanation: The two items are consumed before C1 reacquires the monitor. Since Mesa notification does not reserve a resource and the monitor remains exclusive, C1 must recheck and block again under the lock before acting.