πŸŽ“ BookMCQ
← Back to 5. Process Synchronization

πŸ“ Monitors in Process synchronization (36 MCQs)

High-Level Synchronization Through Monitors

A monitor is a high-level synchronization construct that encapsulates shared data, the procedures operating on that data, and condition variables used for coordination. It belongs to structured process synchronization and provides automatic mutual exclusion between concurrent monitor operations. Only one process or thread is permitted to execute inside a monitor at a time under the classical monitor model.

Why Lock Management Needs Structured Encapsulation

Using separate semaphores throughout a large program makes correct operation ordering difficult to maintain. Programmers may forget to release locks or signal waiting processes. Monitors address this complexity by combining protected data and synchronization operations within one abstraction, reducing direct manipulation of low-level locking protocols and improving modularity.

Monitor Procedures, Mutual Exclusion, and Condition Variables

A process calls a monitor procedure to access protected data. The monitor automatically enforces mutual exclusion. When a required condition is false, the process executes wait on a condition variable and temporarily leaves the monitor. Another process can enter, update the state, and signal the waiting condition when appropriate.

Waiting for an Available Resource Inside a Monitor

Suppose a monitor manages a resource with three available units. A process requesting one unit checks the available count inside a monitor procedure. If the count is zero, it waits on a condition variable. When another process releases a unit and signals the condition, the waiting process resumes and checks availability before proceeding.

Encapsulation, Mutual Exclusion, and Condition Waiting Costs

Monitors simplify synchronization in concurrent applications by centralising shared-state protection and coordination. They are useful for bounded buffers, resource managers, and producer-consumer systems. However, condition-variable semantics differ between implementations, and poorly designed procedures can still cause deadlocks or starvation. Monitor availability also depends on programming-language or runtime support.

Misconceptions About Monitor Execution

'A monitor allows every procedure to execute concurrently' is incorrect because classical monitors provide mutual exclusion. 'Calling signal always transfers control immediately' is incorrect because signal semantics depend on the monitor model. 'Condition variables permanently store notification counts' is incorrect because they coordinate waiting conditions rather than functioning as counting semaphores.

Exam Focus: Monitor Entry and Condition-Variable Behaviour

Identify monitor shared data, procedures, and condition variables in a synchronization design. Trace wait and signal operations and determine which process currently occupies the monitor. Compare monitor synchronization with explicit semaphore locking and distinguish Hoare-style from Mesa-style condition signalling, especially when a waiting process must recheck its condition.

Key Terms of Monitor Synchronization

  • Monitor - Encapsulated mutual-exclusion construct.
  • Condition variable - Mechanism for conditional waiting.
  • wait() - Suspends execution pending a condition.
  • signal() - Notifies a condition waiter.
  • Mutual exclusion - Allows one monitor occupant.
  • Encapsulation - Combines data and operations.
12
Easy
12
Medium
12
Hard

πŸ“ All Monitors in Process synchronization MCQs

Q1. A concurrent program uses a monitor to manage a shared inventory. Which combination best describes the monitor abstraction?

A.A private copy of the inventory for every thread, with no shared operations
B.Shared data, procedures that operate on it, and condition variables for coordination βœ…
C.A processor scheduling queue containing only ready threads
D.A collection of independent counters that remember every notification
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: A monitor groups the shared state with the procedures that manipulate it and condition variables used for coordination. This structure gives callers a controlled interface instead of direct access by design.

Q2. A monitor protects a linked list, but its design allows application code to modify the internal head pointer directly. Which monitor principle has been broken?

A.Condition notifications must always be broadcast
B.Every monitor must contain exactly two procedures
C.A waiting thread must retain the monitor lock
D.Shared internal data should be accessed only through the monitor procedures βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Encapsulation requires callers to use the monitor interface rather than modifying internal state directly. Bypassing that interface also bypasses its mutual-exclusion discipline and can corrupt shared invariants during concurrent execution.

Q3. Two threads simultaneously call a monitor procedure that increments a shared counter using a read, add, and write sequence. What prevents a lost update in the classical monitor model?

A.Only one thread can execute within the monitor at a time βœ…
B.The counter is automatically duplicated for both threads
C.The operating system disables scheduling until the program ends
D.The monitor converts every increment into a separate process
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: The monitor provides mutual exclusion for its procedures, so the two read-modify-write sequences cannot interleave. Both increments are therefore reflected in the shared counter when each call completes under the monitor lock.

Q4. Thread A is executing inside monitor M when thread B calls another procedure of M. What normally happens to B in a classical monitor?

A.B executes concurrently with A because procedures are independent
B.B enters immediately but cannot read shared data
C.B waits outside the monitor until A leaves or waits βœ…
D.B terminates because a monitor accepts only one call in total
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: A classical monitor permits one active thread inside it. A competing caller waits in the monitor entry queue until the current occupant exits or blocks on a condition during that interval.

Q5. A consumer finds a queue empty inside a monitor and calls wait(notEmpty). Which action is essential for the producer to enter and insert an item?

A.The consumer keeps the monitor lock while sleeping
B.The wait operation releases the monitor while the consumer is blocked βœ…
C.The consumer changes the queue count to one before sleeping
D.The producer signals without entering the monitor
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: A condition wait suspends its caller and releases the monitor, allowing another procedure to enter and change the shared state. The waiting thread reacquires the monitor before continuing and releasing its ownership.

Q6. A programmer releases the monitor lock and only afterward registers a thread as waiting on condition spaceAvailable. What race can occur during this gap?

A.The condition variable becomes a counting semaphore
B.The waiting thread receives the lock twice
C.The monitor automatically blocks all producers
D.A producer may signal before the thread is registered, leaving it asleep after space is already available βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: If the state change and notification occur before waiter registration, the notification can be lost and the thread may sleep unnecessarily. An atomic release-and-wait operation closes this gap during the transition.

Q7. After a condition-variable wait is signaled, what must happen before the waiting thread safely resumes a monitor procedure?

A.It must reacquire the monitor lock βœ…
B.It must permanently leave the monitor
C.It must acquire every condition variable in the monitor
D.It must assume the awaited resource is reserved
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: The awakened thread must regain the monitor lock before returning to protected code. This restores mutual exclusion for inspecting shared state, but it does not prove that the waited-for condition is still true.

Q8. A programmer treats condition variable ready as an integer permit count and expects each signal to be saved until a future wait. What is the fundamental error?

A.A condition variable can only be used with two threads
B.A condition variable automatically increments the monitor entry queue
C.A condition variable is a waiting queue, not a persistent notification counter βœ…
D.A condition variable prevents the monitor from storing shared data
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Condition variables coordinate threads that are currently waiting; they do not retain signal credits like counting semaphores. The actual predicate must be stored separately in protected shared data rather than by notification.

Q9. A monitor calls signal(dataReady) when no thread is waiting on dataReady. A thread begins waiting afterward. What should it expect?

A.It immediately consumes the earlier signal
B.It remains waiting until a later notification or relevant state change βœ…
C.It is guaranteed to enter before all other callers
D.It receives one unit from an implicit semaphore
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: A condition-variable signal issued with no waiter is normally discarded. A later thread does not inherit that notification, so it must inspect the shared predicate before deciding whether to wait.

Q10. Four threads are waiting on the same condition variable. A monitor procedure invokes signal once. Without assuming a special policy, what is the expected effect?

A.All four threads enter the monitor together
B.The signaler is terminated after issuing the notification
C.The condition variable stores three unused signals
D.One waiter is made eligible to resume; the others remain waiting βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: A single signal normally selects one waiter, if one exists. It does not wake the entire waiting group, create resource units, or guarantee that the selected waiter will find its predicate true.

Q11. A resource manager has six waiting clients. Its state changes so that several clients may proceed, and it calls broadcast on their condition variable. What does broadcast mean?

A.Every waiting client becomes eligible to resume and must recheck the shared state βœ…
B.Six resource units are created automatically
C.Only the oldest waiter is notified
D.The monitor lock is permanently released to all clients
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Broadcast makes all waiters on the selected condition variable eligible to resume. They still compete to reacquire the monitor and must test the resource predicate before claiming anything when they reacquire it.

Q12. A waiter wakes after signal but finds that the shared predicate is still false. Which design correctly represents the role of a condition variable?

A.The signal itself proves that the predicate is true
B.The waiter should alter the predicate without checking resource availability
C.The predicate belongs in shared state and must be tested independently of the notification βœ…
D.The waiter should continue even though the predicate is false
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: A condition variable reports that a state change may matter; it does not represent the state itself. The monitor must maintain the predicate in shared data and test it before proceeding.

Q13. Under Mesa-style monitor semantics, thread P signals waiting thread Q while both are associated with the same monitor. What happens immediately after the signal?

A.Q takes over the monitor immediately and P is suspended
B.P continues inside the monitor; Q becomes eligible and must later reacquire the monitor βœ…
C.P and Q execute monitor procedures simultaneously
D.Q proceeds without reacquiring the monitor lock
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Mesa signaling uses signal-and-continue behavior: the signaling thread retains the monitor until it leaves or waits. The awakened thread becomes runnable but must compete to reacquire the monitor after the signaling call.

Q14. A Mesa-style monitor contains the statement if queueEmpty then wait(notEmpty). Why is this unsafe for a consumer?

A.A condition variable cannot be used with a queue
B.The if statement always wakes every consumer
C.The monitor lock is never released during wait
D.The queue may become empty again before the awakened consumer reacquires the monitor βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: Under Mesa semantics, another consumer may remove the available item before the awakened thread runs. A while loop rechecks the queue predicate after reacquiring the monitor and prevents an invalid removal.

Q15. In a Hoare-style monitor, a signaler wakes a thread waiting on condition c. Which scheduling action defines the classical signal-and-wait behavior?

A.The waiting thread runs immediately, while the signaler temporarily yields the monitor βœ…
B.The signaler continues until the entire program terminates
C.Both threads execute inside the monitor at the same time
D.The waiting thread is permanently moved to the entry queue
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Hoare-style semantics transfer monitor control immediately to the awakened waiter. The signaler is suspended temporarily, allowing the waiter to rely on the condition established at the signaling point before the signaler continues.

Q16. A monitor uses Hoare-style signal-and-wait semantics. Immediately after a waiting thread resumes because of signal, what can it infer about the condition?

A.The condition may already have been invalidated by another monitor caller
B.The signal only means that the scheduler noticed the thread
C.The condition held when control was transferred to the waiter βœ…
D.The signal has been saved as a permanent permit
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: Under Hoare semantics, the signaled thread runs immediately after the transfer, before another monitor procedure can change the protected state. The condition established by the signaler therefore holds at handoff.

Q17. A team changes a monitor from Hoare-style to Mesa-style signaling but leaves a condition check as a single if statement. Which change is most important?

A.Remove the condition variable and rely on the entry queue
B.Use a while loop so the predicate is checked again after reacquiring the monitor βœ…
C.Allow the waiter to read shared data without the lock
D.Convert each signal into a permanent resource count
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Mesa signaling does not immediately transfer control, so intervening threads can invalidate the predicate. A while loop makes the waiter verify the condition again each time it reacquires the monitor.

Q18. A thread is blocked because another thread is currently executing a monitor procedure. A different thread is blocked after calling wait on condition hasItem. Where are these threads waiting?

A.Both must be in the same condition-variable queue
B.Both are executing inside the monitor but paused
C.The first waits in a condition queue and the second in the entry queue
D.The first waits in the entry queue; the second waits on the condition-variable queue βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: A caller blocked by monitor occupancy waits for entry, while a caller that executes condition wait joins that condition variable queue. These queues represent different reasons for being outside the monitor.

Q19. A trace records the following events: t0, A enters monitor M; t1, B requests M; t2, A calls wait(c); t3, B enters M. What explains B entering at t3?

A.A released the monitor as part of its condition-variable wait βœ…
B.B bypassed mutual exclusion because it arrived second
C.A and B share the monitor simultaneously
D.The condition variable transferred ownership directly to B
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: A condition wait blocks A and releases the monitor, so the entry queue can admit B. The trace preserves mutual exclusion; A is waiting on condition c rather than occupying M.

Q20. A monitor manages three identical devices. Its available count becomes three, and it broadcasts to seven waiting threads. Assuming no other device changes, how many threads can successfully reserve a device?

A.Three, because only three devices are available βœ…
B.Seven, because broadcast wakes every waiter
C.Four, because the first four threads form a group
D.One, because broadcast is equivalent to signal
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Broadcast wakes all seven waiters but creates no devices. At most three can decrement the available count from three to zero; the remaining four must observe the false predicate and wait again.

Q21. A monitor uses one condition variable for two predicates: printerAvailable and scannerAvailable. A signal wakes a thread waiting for the scanner even though only the printer became available. What problem can result?

A.The signal permanently reserves the scanner for that thread
B.The monitor automatically redirects the signal to a printer waiter
C.The awakened thread may find its predicate false while a suitable waiter remains asleep βœ…
D.Both predicates become true because they share a condition variable
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: A shared condition queue can wake a thread whose predicate was not satisfied by the state change. Separate condition variables, or a carefully chosen broadcast, can avoid leaving an eligible waiter asleep.

Q22. A monitor increments availableUnits and then calls signal(unitsAvailable). Why is updating the shared count before signaling a sound ordering?

A.It ensures the condition variable stores the increment permanently
B.It makes every waiting thread run before the signaler
C.It eliminates the need for a predicate check
D.A resumed waiter can inspect the updated state, although it must still verify that a unit remains available βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: The notification should follow the state transition it announces. Updating the count first lets a waiter observe the intended state after reacquiring the monitor, while predicate checking remains essential under the same lock.

Q23. A monitor has two waiters for a resource. The state table is: t0 available=0, waiters=2; t1 release changes available=1; t2 signal wakes one; t3 that waiter reserves the unit. What is the state at t3?

A.available=0, with one thread still waiting βœ…
B.available=1, with both threads still waiting
C.available=2, with no threads waiting
D.available=1, with one thread holding the monitor and one holding the resource
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: The release raises availability to one, signal makes one waiter eligible, and that waiter reserves the unit at t3. The count returns to zero, while the other waiter remains blocked.

Q24. A lock-dependency graph contains edges T1 holds M1 and requests M2; T2 holds M2 and requests M1. What does the cycle establish under exclusive monitor locks?

A.Both threads can enter both monitors concurrently
B.The monitors will automatically release locks in reverse order
C.A circular wait exists, so the two threads can be deadlocked βœ…
D.The system has only a harmless condition-variable notification delay
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: T1 cannot proceed until T2 releases M2, while T2 cannot proceed until T1 releases M1. The cycle creates circular wait and can leave both threads permanently blocked without external intervention.

Q25. A developer writes the following sequence: check predicate while holding M; unlock M; register on condition c; sleep. Another thread may change the predicate and signal between the unlock and registration. What is the precise failure?

A.The signal is converted into a broadcast automatically
B.The waiter can miss the notification and sleep even though the predicate is already true βœ…
C.The signaling thread must wait for the original waiter to finish
D.The monitor permits two threads to hold M together
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The sequence has a lost-wakeup window because the waiter is not yet registered when the signal occurs. A correct condition wait atomically releases the monitor and blocks as one operation.

Q26. A monitor offers getCount() and removeItems(n) as separate procedures. A client calls getCount(), then removeItems(n) using the returned value. Why is the whole client sequence not necessarily atomic?

A.Every monitor call is automatically combined with the next call by the runtime
B.The count cannot change while a monitor exists
C.Condition variables make all client sequences atomic
D.Another monitor call may interleave between the two procedures and change the count βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: Mutual exclusion protects each monitor procedure, not a caller sequence spanning multiple returns and reentries. Another client can change the collection between getCount and removeItems, invalidating the earlier result unless combined into one procedure.

Q27. A monitor returns a pointer to one of its internal mutable records. The caller modifies that record after the method returns, while another thread invokes a monitor update. What is the central flaw?

A.The caller can mutate protected state outside the monitor lock βœ…
B.Pointers cannot refer to records stored in shared memory
C.A monitor must copy every integer before returning
D.The second thread is guaranteed to see a private copy
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: The pointer exposes internal mutable state beyond the monitor boundary. Later caller writes are not serialized with monitor procedures, so shared invariants can be violated despite correct locking inside the monitor.

Q28. A monitor procedure calls an external helper that changes the monitor’s shared counter, but the helper does not acquire the monitor. What conclusion follows?

A.The monitor automatically protects every function called by its procedures
B.The helper is safe because it runs on the same processor
C.The helper can race with protected procedures because its update bypasses monitor exclusion βœ…
D.The counter becomes local to the helper
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The monitor only serializes accesses that follow its synchronization discipline. An external helper that modifies the same counter without protection can interleave with monitor calls and invalidate its invariants unless it follows that discipline.

Q29. A monitor validates an order and updates inventory, then performs a slow network audit before returning. The audit need not be atomic with the inventory update. What is the best design?

A.Hold the monitor lock for the entire network delay to prevent all other orders
B.Finish the consistent inventory update under the monitor, then perform the audit outside it with explicit failure handling βœ…
C.Move the inventory update outside the monitor as well
D.Delete the audit record whenever another thread is waiting
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The validation and inventory change belong in the protected operation, but an independent slow audit need not extend the critical section. Moving it outside reduces contention while requiring defined audit-failure handling.

Q30. A monitor procedure changes shared state and signals a waiter. An exception then bypasses the monitor-exit code, leaving its lock held. Which consequence is most serious?

A.Every waiting thread receives the monitor lock simultaneously
B.The condition signal becomes a stored permit
C.The shared state is automatically rolled back
D.Other threads may be unable to enter the monitor, producing a persistent blockage or deadlock βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: If exceptional control flow fails to release the monitor, no other caller can enter to inspect or repair the state. Reliable cleanup must release the lock on every exit path.

Q31. A monitor correctly protects a resource pool, but the scheduler repeatedly ignores one thread after it has been awakened. Which statement is most accurate?

A.Mutual exclusion guarantees that every waiter eventually runs
B.A signal forces the scheduler to dispatch its recipient next
C.The monitor may preserve safety while the thread still starves because scheduling fairness is separate βœ…
D.Starvation proves that two threads are simultaneously inside the monitor
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Monitor mutual exclusion protects shared-state safety, but does not by itself guarantee CPU time or fair admission. A scheduler can indefinitely postpone a ready waiter without violating mutual exclusion under this scheduling policy.

Q32. A classical monitor serializes every procedure, including a procedure that only reads a shared value. What is the direct consequence of this rule?

A.Read-only procedures can always execute concurrently by definition
B.A read-only call may wait while another monitor procedure is active, even if it would not modify state βœ…
C.The monitor no longer needs an entry queue
D.Every read operation must signal a condition variable before returning
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The classical single-occupant rule applies to monitor procedures regardless of whether they read or write. This simplifies reasoning but may reduce concurrency compared with carefully designed reader-writer access within the protected abstraction.

Q33. A pool monitor starts with five available units. Three waiters are awakened by broadcast; the first two reserve one unit each, and the third has not reacquired the monitor yet. What availability will the third waiter observe if no release occurs?

A.Two units, because broadcast wakes only the first two threads
B.Five units, because broadcast restores the initial value
C.One unit, because only two of the three waiters have run
D.Three units, because two reservations reduce five to three βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: The pool begins with five units and two successful reservations consume two, leaving three. Broadcast changes waiter eligibility only; it does not alter the resource count or reserve units for all awakened threads.

Q34. Consider this Mesa-style trace: A holds M and signals B; A then changes predicate P from true to false and exits; B later reacquires M. What must B do before using the resource guarded by P?

A.Recheck P and wait again if it is false βœ…
B.Proceed because P was true at the signal instruction
C.Assume A transferred the monitor lock immediately
D.Use the resource without consulting shared state
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: The trace shows the signaler continuing after notification and changing P before B runs. Mesa waiters must test the predicate after reacquiring M and return to waiting when it is false.

Q35. A condition variable c has no waiters when signal(c) occurs. A semaphore s has value zero when signal(s) occurs. A later thread calls wait on each object. Which comparison is correct?

A.Both later waits consume a previously stored notification
B.The condition wait blocks, while the semaphore wait can consume the incremented permit βœ…
C.The condition wait succeeds, while the semaphore wait must block
D.Both notifications are discarded because no thread was waiting
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Condition-variable signals are not remembered when no waiter exists. A semaphore signal increments its count, so a later wait can consume that stored permit; this distinguishes their coordination semantics for a future waiter.

Q36. A monitor manages three identical servers. At time t0, available=0 and clients P and Q wait on hasServer. At t1, one server is released and broadcast occurs. P reacquires first and reserves it; Q reacquires afterward. Which outcome is correct?

A.Both clients reserve the same server because both were broadcast
B.Q proceeds because broadcast gives later waiters priority
C.P owns the released server; Q rechecks available=0 and waits again βœ…
D.The server remains available because broadcast does not change resource counts
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Broadcast wakes both clients, but only one server was released. P reserves it under the monitor lock, so Q must observe zero availability and wait again rather than claim the same server.

πŸ”— Related Topics (MCQs)