🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Monitors Usage in Process synchronization (36 MCQs)

Applying Monitor Constructs to Shared Resource Management

Monitor usage involves organising shared data and synchronization operations within a protected module. Applications use monitor procedures to request, modify, and release resources without directly manipulating low-level lock variables. Condition variables allow processes to wait for particular resource states, while automatic monitor mutual exclusion prevents concurrent execution of protected procedures under the classical monitor model.

Why Complex Synchronization Benefits from Monitor Encapsulation

Programs that use multiple mutexes and semaphores can become difficult to verify because resource rules are scattered across different execution paths. A monitor keeps resource state and the operations controlling it together. This reduces accidental unsynchronised access, provides a clearer programming interface, and makes resource-management conditions easier to reason about.

Monitor Entry, Condition Checks, and Resource Release

A process enters a monitor by calling one of its public procedures. The monitor grants exclusive execution, and the procedure checks the current resource condition. If the requested state is unavailable, the process waits on an associated condition variable. Another process changes the state and signals the condition, allowing the waiter to resume according to the monitor's signalling semantics.

Managing a Resource Pool with Two Waiting Processes

Consider a monitor managing a single available printer. Process P1 acquires the printer, while P2 enters a request procedure and waits because the printer is occupied. When P1 releases it, the monitor updates the availability state and signals a waiting process. P2 resumes and checks that the printer is available before acquiring it.

Safer Resource Access and Condition-Checking Requirements

Monitor-based resource management suits shared buffers, printer pools, database objects, and scheduling services. Encapsulation reduces manual lock management, while condition variables support organised waiting. However, condition signalling alone does not guarantee that a resource remains available when a process resumes. Mesa-style monitors therefore require waiters to recheck their conditions using loops.

Misconceptions About Monitor Resource Management

'A monitor automatically grants every waiting process its requested resource' is incorrect because the process must recheck availability. 'A process can execute several monitor procedures simultaneously' is incorrect under classical mutual exclusion. 'Condition signalling always provides fairness' is incorrect because scheduling and waiter-selection policies determine which process resumes.

Exam Focus: Tracing Monitor-Based Resource Allocation

Trace monitor entry, resource-state checks, condition-variable waiting, state updates, and signalling. Determine which process owns a resource before and after each operation. Questions may involve printer pools, bounded buffers, shared counters, and Mesa-style condition loops, or ask how monitor encapsulation differs from separate semaphore operations.

Key Terms of Monitor Usage

  • Monitor procedure - Operation accessing protected monitor state.
  • Monitor entry - Admission into the protected construct.
  • Condition check - Evaluation of resource availability.
  • Waiter - Process suspended on a condition.
  • Signalling - Notification of eligible waiters.
  • Resource pool - Collection of managed resource instances.
12
Easy
12
Medium
12
Hard

📝 All Monitors Usage in Process synchronization MCQs

Q1. A shared inventory service defines its balance and update procedures inside a classical monitor. Two clients call different public procedures at the same time. What does the monitor guarantee?

A.Both clients execute simultaneously whenever they use different fields
B.At most one client executes inside the monitor at a time ✅
C.A client may directly modify internal fields without using a procedure
D.Every caller receives the requested resource immediately
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A classical monitor provides mutual exclusion across its procedures: while one thread executes inside, another must wait at the monitor entry. This guarantee applies to monitor execution, not unrelated code.

Q2. A thread calls signal on condition variable resourceReady when no thread is waiting on that condition. What happens to the notification?

A.It is discarded and does not wake a future waiter ✅
B.It increments a stored count that makes the next wait return immediately
C.The monitor saves one notification for every future caller
D.The condition variable automatically changes the resource state to ready
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A condition variable records waiting threads, not a stored notification count. If signal occurs with no waiter, it has no later effect; a future waiter still blocks until signaled again.

Q3. A file-processing service protects its job queue with a monitor. A method removes a job and then performs a slow network upload before returning. Other threads cannot enqueue jobs during the upload. What is the best improvement?

A.Keep the monitor locked throughout the network call so every operation remains serialized
B.Delay removing the job until after the upload, while allowing other threads to select it
C.Reserve or remove the job under the monitor, then perform the independent upload outside it and update the outcome afterward if needed ✅
D.Allow every worker to upload the same queued job concurrently
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The upload is external and may take seconds, while queue removal requires only a brief protected state change. Reserve or remove the job under the monitor, then upload after leaving it.

Q4. A consumer enters a monitor and discovers that its queue is empty. Which operation lets it sleep while allowing a producer to enter and add an item safely?

A.Keep the monitor lock and repeatedly inspect the queue
B.Release the monitor manually, then register for a condition wait in a separate operation
C.Return an empty result and prevent producers from entering until the consumer retries
D.Wait atomically on the notEmpty condition, releasing the monitor while blocked ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The condition wait must atomically place the consumer on the condition queue and release the monitor. A producer can then enter, add an item, and signal without a lost-wakeup gap.

Q5. Which statement correctly distinguishes a condition variable from a counting semaphore?

A.A condition variable has no persistent count; wait blocks and a signal with no waiter is not saved ✅
B.A condition variable always stores one permit for the next arriving thread
C.A condition-variable wait blocks only when its integer count reaches zero
D.A condition-variable signal must wake every thread waiting in the monitor
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Unlike a semaphore, a condition variable has no persistent count. Its wait operation always blocks, while signal with an empty waiter queue is discarded rather than saved for a later caller.

Q6. A bank monitor has a condition variable for withdrawals waiting until the balance is sufficient. A deposit signals a waiting withdrawal. Why must the withdrawal test the balance again after waking?

A.The signal always subtracts the deposited amount from the balance
B.A condition wait permanently copies the old balance into the waiting thread
C.The monitor lock remains released even after the withdrawal resumes
D.Another withdrawal may change the balance before this waiter reacquires the monitor, so it must test the predicate again ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Under signal-and-continue semantics, the depositing thread may continue running after signaling. Other withdrawals can change the balance before the waiting thread resumes, so the withdrawing method must verify the predicate again under the monitor lock.

Q7. A monitor manages five connections. Two clients each acquire two connections, and a third client requests two connections as one atomic operation. If the first allocations remain active, what should happen to the third request?

A.It should take the one free connection and wait while holding it for another
B.It should wait without taking a partial allocation until two connections are available ✅
C.It should proceed because the pool originally contained five connections
D.It should change the available count to two because its request is valid
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Two acquisitions consume four connections, leaving 5−4=15-4=1. A request for two cannot be satisfied; an atomic pool operation should wait without allocating one connection and holding it while awaiting another.

Q8. A cache monitor exposes one method to check whether a key exists and another to insert it if absent. Two clients call these methods separately and both initially observe that the key is absent. What is the safest correction?

A.Allow duplicate entries and overwrite whichever value was inserted first
B.Assume the monitor makes the two separate method calls one indivisible operation
C.Combine the existence check and insertion into one monitor procedure ✅
D.Remove synchronization from insertion because both clients performed a check
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Each method is mutually exclusive only while it runs. Between the check and insert calls, another thread can insert the same key, so the whole check-then-act operation must be one monitor procedure.

Q9. A consumer checks that a queue is empty, releases the monitor lock, and only afterward registers itself as waiting. A producer can insert and signal during this gap. What failure can result?

A.The consumer may miss the signal and sleep even though the queue contains an item ✅
B.The producer must wait until the consumer has removed an item
C.The queue is guaranteed to discard the newly inserted item
D.The monitor automatically stores the signal for the unregistered consumer
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The producer may signal after the consumer releases the lock but before the consumer is actually queued. That notification is lost, leaving the consumer asleep despite a nonempty queue; wait registration and lock release must be atomic.

Q10. A monitor releases a resource by increasing availableCount. Which order should the method follow to wake a thread waiting for available resources?

A.Signal first, then update the count after the awakened thread finishes
B.Release the monitor, update the count without protection, then signal later
C.Update the protected count first, then signal the appropriate condition variable ✅
D.Signal repeatedly without changing the count so a waiter can proceed
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The producer must first increment the available count while holding the monitor, then signal the condition. Otherwise the waiter may wake, see the old zero count, and immediately block again.

Q11. A Mesa-style monitor contains this logic: if (available == 0) wait(resourceReady); acquireResource(); A reviewer says it is correct because signal wakes a waiter. What is the flaw?

A.A monitor condition variable cannot be used with resource counts
B.The signal operation automatically reserves a resource for the awakened thread
C.A Mesa monitor immediately transfers execution to the awakened waiter
D.The condition may become false before the waiter resumes, so the code must use while and recheck ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The flawed if check assumes the condition stays true after notification. Under Mesa semantics the notifier continues, so another thread may consume the resource first; use while and recheck after reacquiring the monitor.

Q12. Under Hoare-style monitor semantics, what happens immediately after a thread signals a condition that has a waiting process?

A.The signaling thread continues and the waiter competes later for monitor entry
B.The signaled waiter runs immediately, while the signaling thread is suspended ✅
C.Both threads execute monitor statements concurrently until one exits
D.The signal is saved as a permit for the next process to call wait
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Hoare-style signal-and-wait semantics immediately transfer monitor execution to the signaled waiter. The signaling process is suspended until the waiter leaves or waits, so the condition is guaranteed at handoff time.

Q13. A producer signals notEmpty after adding an item, but continues executing inside a Mesa-style monitor. Before the consumer resumes, another consumer may remove the item. What must the awakened consumer do?

A.Assume the signal reserves the item and remove it unconditionally
B.Proceed without reacquiring the monitor because the producer has signaled
C.Reacquire the monitor and recheck the queue predicate in a loop before removing ✅
D.Wait for a second signal even if the queue is still nonempty
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: In Mesa-style signaling, the producer retains the monitor after signaling. It may change the state again before the consumer resumes, so the consumer must test the availability predicate again before proceeding.

Q14. A queue monitor records occupancy after each event as (time, items): (0,0); (1,2); (2,1); (3,3); (4,2); (5,4). At which recorded time is the queue fullest?

A.Time 5, when occupancy is 4 ✅
B.Time 3, when occupancy is 3
C.Time 1, when occupancy is 2
D.Time 4, when occupancy is 2
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The listed occupancies are 0, 2, 1, 3, 2, and 4. The maximum is 4 at time 5, so the graph indicates the queue is fullest at the final recorded point.

Q15. A resource monitor has two waiters: one needs at least one unit, while another needs at least four. The available count rises from zero to one, and signal wakes one arbitrary waiter. Which design best avoids leaving the eligible waiter asleep because the other waiter was selected?

A.Use one arbitrary signal and let the selected waiter proceed without checking
B.Make the four-unit waiter acquire one unit immediately and retain it while waiting
C.Remove the condition checks and wake only the first thread created
D.Use separate condition queues for distinct predicates, or broadcast and require every waiter to recheck its predicate ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The single signal may wake the waiter needing four units, whose predicate is still false, while the eligible one-unit waiter remains asleep. Separate condition queues or broadcast plus predicate loops prevent this selection mismatch.

Q16. A monitor correctly prevents concurrent execution of its procedures, but one client can remain blocked indefinitely while newer clients repeatedly receive service. Which property is not guaranteed by mutual exclusion alone?

A.Protection against two procedures executing inside the monitor simultaneously
B.Fair admission and eventual service for every waiting client ✅
C.Encapsulation of monitor state behind its procedures
D.Exclusive access to the protected state during a procedure call
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Automatic mutual exclusion prevents simultaneous execution of monitor procedures, but it does not choose a fair admission order. A correct monitor can therefore still starve a client under an unfair scheduling policy.

Q17. A connection pool contains six connections. One is already in use, and a client atomically acquires three more. Assuming no other requests intervene, how many connections remain available?

A.Zero
B.One
C.Two ✅
D.Three
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: After one is already in use, five connections remain free. Acquiring three changes availability to 5−3=25-3=2. The monitor must perform the count update and ownership assignment as one protected operation.

Q18. A monitor's available-resource count is recorded as (time, free units): (0,0); (1,1); (2,2); (3,1); (4,3); (5,2). A waiting client requires three units atomically. At which earliest recorded time can it proceed?

A.Time 4 ✅
B.Time 2
C.Time 3
D.Time 5
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A request for three can first be satisfied at time 4, when the recorded count reaches 3. Earlier points show fewer than three free resources, so the waiter must continue waiting.

Q19. A monitor manages a pool of connections. A client needs three connections, but only two are free. Which allocation policy avoids making this client hold one connection while waiting for the others?

A.Allocate one connection immediately and let the client wait while holding it
B.Grant all requested connections together or grant none until the request can be satisfied ✅
C.Let the client change the pool count to three before acquiring
D.Allow the client to use connections owned by other clients temporarily
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The pool should grant all requested resources together or none. Waiting without a partial allocation avoids making the requester hold one connection while waiting indefinitely for the remaining connections resources.

Q20. A monitor-based queue contains one job and has four waiting consumers. The producer broadcasts on notEmpty. What happens when the consumers resume and compete for the monitor?

A.Each consumer receives a separate copy of the job
B.The broadcast itself removes the job before any consumer enters
C.All consumers remove the same job because they woke together
D.One consumer removes the job; the others find the queue empty and wait again ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Broadcast wakes all eligible consumers, but the monitor lock still serializes removal. The first consumer takes the sole job; others recheck the empty-queue predicate and return to waiting inside the monitor.

Q21. A monitor's release method increases the available-resource count but never signals the condition variable used by blocked clients. What may happen even though the resource is now free?

A.The resource count automatically wakes every blocked client
B.The monitor deletes the wait queue when the count becomes positive
C.Existing waiters may remain asleep because changing shared state does not itself wake condition waiters ✅
D.A new client is prevented from entering the monitor permanently
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A condition variable does not watch shared state or wake threads automatically. After increasing availability, the release method must signal an appropriate waiter; otherwise existing waiters may remain blocked indefinitely.

Q22. A reader obtains several account fields through separate monitor calls. A writer updates all fields in one call, and the reader sees a mixture of old and new values. What explains this result?

A.Mutual exclusion for each call does not make the reader's entire sequence an atomic snapshot ✅
B.The writer necessarily executed two monitor methods simultaneously
C.Monitor procedures cannot protect fields that belong to the same record
D.A monitor automatically copies every record when a method begins
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Separate protected calls do not create an atomic snapshot across the entire read. The update can occur between calls, producing a combination of values from different versions; provide one snapshot operation.

Q23. A monitor method reserves a printer and then waits for a remote approval service while keeping the monitor locked. Other clients cannot use unrelated printers. Which design is usually preferable when the operation's invariants permit it?

A.Keep the monitor locked during every remote operation to prevent unrelated activity
B.Record a reservation under the monitor, perform the remote call outside it, then reacquire the monitor and validate the outcome ✅
C.Release the printer reservation before calling the service, without recording who owns it
D.Allow all clients to modify the printer table without synchronization
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The network call can block for a long time while unrelated clients need the monitor. Record a reservation under protection, release the monitor for external work, then reacquire and validate the result.

Q24. A monitor method owns a non-reentrant lock and calls another public method that tries to acquire that same lock again. What is the likely result?

A.The lock is automatically converted into a counting semaphore
B.The nested method executes concurrently with the outer method
C.The thread blocks on a lock it already owns, causing self-deadlock ✅
D.The monitor releases the lock whenever one method calls another
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The outer method already owns the non-reentrant lock. Reacquiring it in the nested call blocks the same thread on its own lock; use an internal helper that assumes monitor ownership or avoid reacquisition.

Q25. A monitor implementation releases its lock only along the normal return path. An exception occurs before that statement, and later callers block forever. Which correction addresses the defect?

A.Catch the exception and ignore it while leaving the lock held
B.Use guaranteed cleanup, such as a finally block or scoped locking, to release the lock on every exit path ✅
C.Remove the lock from all monitor methods
D.Require callers to acquire the monitor lock a second time before retrying
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The flawed implementation releases the lock only on normal return. An exception bypasses that statement, leaving every later caller blocked; use guaranteed cleanup such as a finally block or scoped locking.

Q26. A job monitor tracks queued jobs and active jobs. Its trace is (event, queued, active): (0,4,0); (1,3,1); (2,2,2); (3,3,1); (4,2,2); (5,1,3). How many jobs are outstanding at event 5?

A.One
B.Three
C.Five
D.Four ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: At event 5, one task remains queued and three are active, giving 1+3=41+3=4 outstanding tasks. The state accounting must include both queued and in-progress jobs to preserve the service invariant.

Q27. A monitor removes a job from its queue and then records the job identifier in an active-job set. If the second update fails, what is the most important design requirement?

A.Make the state transition atomic or provide recovery so the job cannot disappear from both representations ✅
B.Ignore the error because the queue removal has already succeeded
C.Insert the job into the queue a second time regardless of its status
D.Release the monitor before either update and allow arbitrary interleavings
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Removing a job before recording its active ownership can make it disappear from both visible states if the second update fails. Make the transition atomic or define compensating recovery for consistency.

Q28. A monitor protects a deposit(amount) procedure. The method is synchronized correctly, but its contract allows only positive deposits. A caller supplies -20. What should the monitor do?

A.Accept the input because mutual exclusion guarantees that it is safe
B.Convert the amount to zero without reporting the invalid request
C.Allow the caller to update the balance directly instead
D.Reject the negative amount before changing the balance ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The lock prevents interleaving, not invalid requests. The monitor must enforce its method contract by rejecting a negative amount before changing the balance, preserving both synchronization and application invariants consistently.

Q29. A resource monitor offers isFree(resource) and acquire(resource) as separate calls. A client checks that a printer is free, but another client acquires it before the first client calls acquire. What is the best fix?

A.Increase the number of condition variables without changing the calls
B.Let both clients acquire the printer and resolve ownership afterward
C.Combine the availability check and ownership assignment into one monitor procedure ✅
D.Return the availability result as a permanent reservation token without changing monitor state
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A true availability result can become stale as soon as the method returns. Another caller may claim the resource first; combine checking and claiming in one monitor procedure to make ownership atomic.

Q30. A monitor wakes its oldest waiter first, but does not reserve the resource for that waiter. New arrivals repeatedly enter first and acquire the resource. What does this reveal?

A.Selecting a waiter for notification alone does not guarantee fair resource admission ✅
B.The oldest waiter necessarily owns the resource as soon as it is signaled
C.A monitor's entry queue cannot contain newly arriving clients
D.The resource is no longer protected by mutual exclusion
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Selecting the oldest waiter for notification does not reserve the resource. A new arrival may enter first and repeatedly win the race, so fairness requires an admission policy that prevents overtaking.

Q31. A service records (time, newer requests completed while the oldest waiter remains blocked): (0,0); (1,2); (2,4); (3,6); (4,8); (5,10). What does this pattern indicate?

A.The oldest waiter is receiving service at the same rate as new arrivals
B.The monitor has violated mutual exclusion because more than one request completes
C.The condition variable has stored too many notifications
D.Newer requests repeatedly bypass the oldest waiter, so admission should prevent indefinite overtaking ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Newer work increases from zero to ten completed requests while the original waiter receives no service. This pattern shows repeated bypass, so a fair queue must prevent newcomers from overtaking indefinitely.

Q32. A connection pool has two free connections. Its wait queue contains W1 requesting three connections, followed by W2 and W3 each requesting one. If the monitor enforces strict FIFO, what trade-off appears?

A.W2 and W3 immediately bypass W1 without affecting fairness
B.All three requests are satisfied because two free connections can satisfy three requests
C.W1 receives two connections immediately and waits for the third while holding them
D.Strict FIFO can leave capacity idle behind W1; allowing bypass improves use but may starve the larger request without a fairness rule ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Strict FIFO leaves two free connections idle because the first request needs three; allowing later one-unit requests to pass improves utilization but can starve the large request without a fairness rule.

Q33. A banking service uses one global monitor for unrelated accounts, so a slow operation on account A blocks updates to account B. Which redesign can improve concurrency without abandoning protection?

A.Remove all synchronization and rely on each client to avoid conflicting updates
B.Use finer-grained protection for independent accounts and define a consistent lock order for transfers involving multiple accounts ✅
C.Keep the global monitor and perform external network calls while holding it
D.Allow every account update to modify a shared global balance directly
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A global monitor serializes unrelated account operations. Separate protection allows independent accounts to proceed concurrently, but transfers touching multiple accounts need a consistent lock order to avoid deadlock between transactions.

Q34. A service never corrupts shared data, but some clients wait indefinitely while others continue receiving service. Which conclusion is most accurate?

A.Mutual exclusion may preserve safety even though liveness or fairness fails ✅
B.The service must have a data race because any waiting is unsafe
C.Correct monitor locking guarantees that every client eventually runs
D.An indefinitely waiting client proves that the monitor has no mutual exclusion
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Correct mutual exclusion establishes a safety property by preventing conflicting concurrent access. It does not ensure every waiting client eventually runs; admission and scheduler policies determine liveness and starvation risk.

Q35. A logging thread reads monitor-protected fields without entering the monitor. It sometimes reports combinations that never existed together. What is the best correction?

A.Increase the logging frequency so every field is read faster
B.Expose a protected snapshot operation or make the logger follow the same synchronization discipline ✅
C.Allow the logger to modify fields before recording them
D.Read each field twice and choose whichever value appears more often
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The logger ignores the monitor's synchronization boundary, so it can read fields on opposite sides of an update. Expose a protected snapshot method or apply the same locking discipline to logging.

Q36. A monitor returns a direct reference to its internal mutable resource table. A client changes the table without calling any monitor procedure. What design principle was lost?

A.Condition variables can no longer wake waiting threads
B.The monitor's entry queue becomes a counting semaphore
C.Encapsulation was bypassed; return an immutable copy or expose controlled operations that preserve internal invariants ✅
D.Mutual exclusion now applies automatically to the client's direct writes
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Returning a direct reference to internal mutable state lets callers change it without executing monitor procedures. Return an immutable copy or expose controlled operations so every change preserves the monitor's invariants.

🔗 Related Topics (MCQs)