🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Process synchronization in Windows (36 MCQs)

Windows Kernel Objects for Thread Synchronization

Windows provides synchronization facilities through kernel dispatcher objects, user-mode synchronization primitives, and interlocked processor operations. These mechanisms coordinate threads accessing shared resources and support event notification, mutual exclusion, and resource counting. Common facilities include mutexes, semaphores, events, critical sections, and slim reader-writer locks, allowing applications and system components to manage concurrent execution.

Why Windows Needs Multiple Synchronization Mechanisms

Different applications require different synchronization behaviour. A short shared-memory operation benefits from a lightweight lock, while a thread waiting for a device event may require a blocking notification mechanism. Providing several synchronization primitives allows Windows software to balance kernel-transition costs, fairness, ownership requirements, and the duration of protected operations.

Critical Sections, Mutexes, Semaphores, and Events

A Windows critical section provides mutual exclusion between threads within one process and commonly uses efficient user-mode operations before blocking when necessary. A mutex can coordinate access across processes, while semaphores represent multiple permits. Event objects notify waiting threads, and interlocked functions perform supported atomic updates to shared memory.

Coordinating Two Threads with a Windows Mutex

Suppose threads T1 and T2 in separate processes need access to a shared system resource. Both open the same named mutex and attempt to acquire it. T1 obtains ownership and performs its operation. T2 waits until T1 releases the mutex, after which T2 can acquire the resource and continue.

Blocking Efficiency, Ownership, and Kernel Overhead

Windows synchronization mechanisms support concurrent applications, device services, and system components. User-mode critical sections reduce unnecessary kernel transitions for uncontended locks, while dispatcher objects support blocking and notification. However, excessive contention increases waiting and context-switch overhead. Incorrect lock ordering can cause deadlocks, and abandoned mutex ownership requires careful recovery handling.

Misconceptions About Windows Synchronization Objects

'A Windows critical section can synchronize unrelated processes directly' is incorrect because it is process-local. 'An event object automatically protects shared data' is incorrect because it provides notification rather than mutual exclusion. 'Every mutex acquisition is a kernel-mode operation' is incorrect because implementation paths may optimise uncontended operations.

Exam Focus: Matching Windows Primitives to Synchronization Needs

Compare critical sections, mutexes, semaphores, events, and interlocked operations by their purpose and scope. Identify whether a primitive provides mutual exclusion, counting, notification, or atomic updating. Questions may distinguish process-local critical sections from cross-process mutexes, examine blocking behaviour, and evaluate suitable mechanisms for short and long critical sections.

Key Terms of Windows Synchronization

  • Critical section - Process-local mutual-exclusion mechanism.
  • Mutex - Ownership-based exclusive lock.
  • Semaphore - Counts available resource permits.
  • Event object - Notifies waiting execution activities.
  • Interlocked operation - Atomic shared-memory operation.
  • Dispatcher object - Kernel object supporting synchronization.
12
Easy
12
Medium
12
Hard

📝 All Process synchronization in Windows MCQs

Q1. Three threads in one Windows process update the same in-memory account record. Which primitive is designed to provide exclusive access among those threads with low overhead when uncontended?

A.A process-local critical section ✅
B.A manual-reset event used without a lock
C.A semaphore initialized to a very large count
D.A waitable timer
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A critical section provides mutual exclusion among threads in the same process. Its uncontended path is lightweight, while contention can make a thread wait, so it suits short in-process updates better than a cross-process kernel mutex.

Q2. Two independent Windows processes map the same shared-memory region and must prevent simultaneous updates. Which choice directly supports mutual exclusion across their process boundary?

A.A separate unnamed critical section in each process
B.A named mutex opened by both processes ✅
C.A condition variable allocated separately in each process
D.A volatile Boolean stored in each process
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Separate critical-section objects have independent process-local state and cannot coordinate the two processes. A named mutex lets both processes refer to the same synchronization object and take exclusive ownership of it.

Q3. A Windows service manages six identical database connections. At most six worker threads may use a connection simultaneously, and each completed operation returns one available connection. Which primitive best represents this limit?

A.A manual-reset event
B.A critical section
C.A counting semaphore initialized to six ✅
D.A condition variable without a counter
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A counting semaphore represents a finite number of available permits. Initializing it to six allows up to six successful waits before the count reaches zero; releasing a permit makes capacity available again.

Q4. During application shutdown, every worker waiting for a stop notification should be released, and later waiters should also observe the notification until it is cleared. Which event behavior fits?

A.An auto-reset event, because it remains signaled until all workers finish
B.A mutex, because it broadcasts ownership to every waiter
C.A semaphore with count one, because it wakes every waiter
D.A manual-reset event, reset explicitly after the shutdown condition is handled ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: A manual-reset event remains signaled until the program resets it, allowing multiple current and later waiters to proceed. An auto-reset event normally releases one waiter and then clears its signaled state.

Q5. A developer signals a Windows event before modifying a shared structure and assumes the event itself prevents two workers from changing that structure simultaneously. Which statement is correct?

A.An event provides notification, not mutual exclusion for the shared structure ✅
B.An event automatically locks every variable accessed by a released waiter
C.An event guarantees that only its creator can access shared memory
D.An event converts simultaneous writes into atomic transactions
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: An event communicates that a state or occurrence should be noticed; it does not grant exclusive ownership of ordinary data. Shared updates still need a lock or suitable atomic protocol to prevent races.

Q6. A monitoring thread calls WaitForSingleObject on a process handle representing a helper process. What condition normally makes that process object become signaled?

A.The helper process terminates ✅
B.The helper process receives a higher scheduling priority
C.The helper process creates its first thread
D.The helper process opens a named mutex
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A process handle is waitable. Its object becomes signaled when the represented process terminates, allowing the monitoring thread to block efficiently until completion rather than repeatedly polling process state without busy waiting.

Q7. Thread T owns a Windows mutex and calls a wait function on that same mutex again. What should it normally expect?

A.The mutex is destroyed after the first acquisition
B.The second wait always blocks until another thread releases it
C.The owning thread can acquire it recursively and must release it once for each successful acquisition ✅
D.The mutex changes into a counting semaphore
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Windows mutex ownership is recursive for its owning thread. A repeated successful wait increases the ownership recursion count, so the thread must call ReleaseMutex the corresponding number of times before another thread can acquire it.

Q8. WaitForSingleObject returns WAIT_ABANDONED for a mutex. What does the waiting thread know?

A.It timed out and does not own the mutex
B.The mutex was deleted before the wait completed
C.The previous owner released the mutex normally
D.It acquired the mutex, but the previous owner terminated without releasing it and protected data may be inconsistent ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: WAIT_ABANDONED reports that the previous owner terminated while owning the mutex. The waiting thread acquires ownership, but it must inspect and recover the protected resource because an update may have stopped midway.

Q9. A thread enters the same Windows critical section twice while executing nested helper functions, then leaves it twice. Which behavior is expected?

A.The critical section supports recursive entry by its owning thread, with matching leave operations required ✅
B.The second entry is guaranteed to deadlock the thread
C.The second entry lets another process acquire the object
D.The first leave permanently deletes the critical section
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Windows critical sections are recursive for the owning thread. Nested code can enter the same object again, but each successful entry must be matched by a leave before other threads can enter.

Q10. A multiprocessor application sets a spin count for a critical section that is usually held for only a few instructions. What is the intended effect when another thread owns it?

A.The waiting thread runs the critical section concurrently
B.The waiting thread briefly checks for release before blocking, potentially avoiding a sleep for very short lock holds ✅
C.The critical section becomes cross-process
D.The spin count guarantees a FIFO acquisition order
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Spinning lets a contending thread poll briefly for the lock to become free before entering a blocking wait. It can help when hold times are very short, but it consumes processor time and gives no FIFO guarantee.

Q11. Two Windows threads acquire two mutexes in opposite orders. Thread A holds M1 and waits for M2, while Thread B holds M2 and waits for M1. Which design change directly removes this circular wait pattern?

A.Increase both mutex timeouts to INFINITE
B.Replace both mutexes with manual-reset events
C.Require every thread to acquire M1 before M2 ✅
D.Call Sleep before each wait without changing acquisition order
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A consistent global lock order prevents the two threads from forming the shown cycle. If every path acquires M1 before M2, a thread cannot hold M2 while waiting for M1 in this protocol.

Q12. Two processes create or open the same named mutex, but one receives an access-denied error. What should the developer examine first?

A.Whether both processes use the same CPU core
B.Whether the mutex name contains a numeric character
C.Whether the mutex was signaled before either process started
D.The synchronization object security descriptor and requested access rights ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Named synchronization objects are subject to Windows access control. Matching the object name does not bypass its security descriptor; the process token and requested access rights must permit the operation.

Q13. A Windows semaphore currently has a count of three. A thread successfully waits on it, and no other operation occurs. What is the new count?

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

📖 Explanation: A successful wait on a semaphore consumes one permit. Starting from three, the count becomes two; the object becomes nonsignaled only when its count reaches zero for subsequent waiting threads.

Q14. A semaphore has current count five and maximum count five. ReleaseSemaphore is called to add one permit and reports failure. What is the correct interpretation?

A.The count became six despite the error
B.The release would exceed the maximum, so no additional permit should be assumed ✅
C.The semaphore converted itself into an event
D.All waiting threads acquired permits automatically
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A semaphore cannot exceed its configured maximum count. When a release would raise the count beyond that limit, the call fails; code must check the result rather than assume a permit was added.

Q15. A producer calls SetEvent repeatedly on an auto-reset event while the event is already signaled and no worker is waiting. Why can these calls fail to represent every queued job?

A.An auto-reset event is a kernel mutex with recursive ownership
B.Each SetEvent call creates a separate event object
C.The event records a signaled state, not an accumulating count of pending notifications ✅
D.The event can only be signaled by a waiting thread
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: An auto-reset event stores a state rather than a permit count. Repeated signals can coalesce while it is already signaled, so a producer that must account for every item should use a queue with a counting protocol.

Q16. A manual-reset event is signaled while four threads are waiting. What happens to the event state after those waiters are released?

A.It is always destroyed
B.It remains signaled until a thread explicitly resets it ✅
C.It becomes a semaphore with count four
D.It automatically returns to nonsignaled after releasing the first waiter
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A manual-reset event stays signaled after releasing waiting threads. Additional threads can also pass while it remains signaled; the application must call ResetEvent when the condition should no longer be treated as available.

Q17. A work queue may contain several jobs, but a producer uses one auto-reset event to wake consumers. A consumer wakes, removes one job, and returns to waiting while jobs remain. What design weakness is exposed?

A.The event notification is not a count of queued jobs, so remaining work can be left without a corresponding wakeup ✅
B.The auto-reset event guarantees every queued job is assigned to a distinct consumer
C.The event automatically protects the queue from concurrent removal
D.The consumer must release the event like a mutex
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: An auto-reset event can coalesce notifications and does not track queue length. The design should drain the queue while work remains, reliably signal again, or use a semaphore whose permits correspond to available jobs.

Q18. A service limits simultaneous access to four identical devices using a semaphore initialized to four. Four threads each complete a successful wait and keep their permits. What happens when a fifth thread waits?

A.It also proceeds because four is the initial count, not a limit
B.It blocks until a permit is released ✅
C.It resets the count to four
D.It takes ownership of the semaphore permanently
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Each successful wait consumes one of the four permits. Once all are held, the semaphore count is zero and another waiter blocks until a thread releases a permit after finishing its device operation.

Q19. A producer waits on a free-slot semaphore for a bounded queue, reserves one slot, then detects an error before inserting anything. Which recovery preserves correct accounting?

A.Release the items semaphore even though no item was inserted
B.Leave the reservation consumed permanently in every error case
C.Restore the free-slot permit and do not advertise a nonexistent item ✅
D.Set both semaphore counts to the queue capacity
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The free-slot wait reserved capacity, but the failed insertion did not create a consumable item. Recovery should return the reservation to the free-slot count and must not increase the available-item count.

Q20. A manual-reset event releases two worker threads at once. Both then modify the same shared list without acquiring a lock. What is the main defect in this design?

A.Manual-reset events always serialize the released threads
B.The list becomes read-only when an event is signaled
C.A successful wait gives each thread exclusive ownership of every shared variable
D.The event provides notification but does not protect the list from concurrent updates ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: A manual-reset event may release multiple waiters, but it does not serialize their subsequent work. The list still needs a critical section, mutex, or other compatible protection around conflicting modifications.

Q21. Two Windows threads increment the same aligned counter with InterlockedIncrement. What property does this operation provide for the increment itself?

A.An atomic read-modify-write update that prevents lost increments ✅
B.Mutual exclusion over every statement in the calling function
C.A guarantee that the counter never overflows
D.FIFO scheduling for all threads touching the counter
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: InterlockedIncrement performs the increment as one atomic operation on the target variable. It prevents competing increments from overwriting one another, but it does not automatically protect unrelated data or a larger multi-step invariant.

Q22. A program atomically increments a shared item count and then separately inserts the item into a linked list. A consumer can observe the new count before the insertion completes. What was incorrectly assumed?

A.Interlocked operations can only be used with events
B.Atomicity of one variable update does not make the entire list-and-count invariant atomic ✅
C.A linked list cannot be shared between Windows threads
D.The consumer should assume the item is already fully linked
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The interlocked increment protects only the counter update. The related list change and count must be coordinated as one invariant, for example under a lock or a carefully designed lock-free protocol.

Q23. A Windows program marks a shared flag volatile and assumes the producer's several writes to a structure become one indivisible transaction when the consumer sees that flag. Why is this assumption unsafe?

A.Volatile automatically creates a kernel mutex
B.Volatile ensures every multi-field update is indivisible
C.Volatile alone does not provide a complete atomicity and memory-ordering protocol for interthread synchronization ✅
D.Volatile makes the consumer run immediately after the producer
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Volatile does not turn several writes into one indivisible transaction or protect the structure invariant. Use a lock or carefully designed atomic publication protocol so the consumer observes one consistent state.

Q24. A compare-and-swap loop updates a shared pointer. The pointer changes from address A to B and back to A before the original thread retries. Why can the comparison miss this history?

A.Compare-and-swap never compares pointer values
B.Windows automatically changes every pointer after a failed retry
C.A pointer cannot be assigned the same address twice
D.The observed value equals A again, so an untagged comparison may succeed despite an intervening change ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: This is the ABA problem: the value appears unchanged even though it changed and returned to its earlier representation. Tagged versions, hazard pointers, or other safe reclamation techniques may be needed, depending on the design.

Q25. A thread has entered a critical section exactly once and calls SleepConditionVariableCS. What happens as it enters the condition-variable wait?

A.The critical section is released atomically as the thread begins sleeping, then reacquired before the call returns ✅
B.The critical section remains held until the timeout expires
C.The condition variable transfers critical-section ownership permanently
D.The waiting thread is terminated and recreated when awakened
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: SleepConditionVariableCS atomically releases the supplied critical section while the thread enters the wait. When awakened or timed out, the function reacquires that critical section before returning to the caller under the associated lock.

Q26. A worker waiting on a Windows condition variable wakes, reacquires its lock, and discovers that another worker already consumed the available item. What should the first worker do?

A.Proceed because a wakeup proves the item is still available
B.Recheck the condition predicate in a loop and wait again if it is false ✅
C.Release the lock permanently
D.Assume condition variables cannot wake spuriously
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Wakeups can be spurious or stolen by another thread that runs first. The predicate, not the wakeup alone, determines whether work is available, so the worker should recheck it while holding the associated lock.

Q27. A queue receives one item and calls WakeAllConditionVariable when twelve consumers are waiting. Most awakened consumers find the queue empty after one wins the item. What is the likely performance cost?

A.The condition variable becomes permanently signaled
B.All twelve consumers gain ownership of the same item
C.Unnecessary wakeups cause lock contention and extra scheduling activity ✅
D.WakeAllConditionVariable converts the queue into a semaphore
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: WakeAllConditionVariable releases all waiters, even though one item may satisfy only one consumer. The others contend for the lock, recheck the predicate, and sleep again, creating avoidable scheduling and synchronization overhead.

Q28. A team allocates a Windows condition-variable structure independently in two processes and expects a wake in one process to release a waiter in the other. Why is this design invalid?

A.Condition variables are named kernel objects shared automatically by all processes
B.Condition variables work only when each process has exactly one thread
C.A condition variable requires a counting semaphore as its storage
D.Windows condition variables are user-mode objects for threads within one process, not interprocess synchronization objects ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Windows condition variables are process-local user-mode synchronization primitives. Separate structures in different processes do not form one shared wait channel; cross-process coordination needs an appropriate shared synchronization object, such as a named mutex.

Q29. A cache is read frequently and updated occasionally by threads in one Windows process. Readers may run together, but a writer must exclude all readers and other writers. Which primitive directly matches this access pattern?

A.A slim reader-writer lock, using shared mode for readers and exclusive mode for writers ✅
B.An auto-reset event used as a reader count
C.A mutex acquired in shared mode by every reader
D.A semaphore whose count is increased by every writer
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: An SRW lock supports shared acquisition by multiple readers and exclusive acquisition by a writer. It is process-local and nonrecursive, so code must follow its ownership rules and avoid assuming recursive acquisition.

Q30. A performance test reports these pairs of (worker threads, completed operations per second): (1,100), (2,192), (4,350), (8,515), (16,520). Between which two measurements does throughput gain nearly disappear?

A.From 1 to 2 threads
B.From 8 to 16 threads ✅
C.From 2 to 4 threads
D.From 4 to 8 threads
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Throughput rises from 515 to only 520 operations per second when workers increase from eight to sixteen. The near-flat final interval suggests contention or another shared bottleneck has largely removed scaling benefit.

Q31. A lock benchmark gives (critical-section hold time in milliseconds, mean waiter delay in milliseconds): (1,0.1), (2,0.3), (4,1.0), (8,3.7), (16,12.5). What delay is measured at an eight-millisecond hold time?

A.1.0 milliseconds
B.12.5 milliseconds
C.3.7 milliseconds ✅
D.0.3 milliseconds
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Read the pair whose first coordinate is eight: it is (8,3.7). Therefore the measured mean waiter delay is 3.7 milliseconds; the first coordinate is the hold time, not the delay.

Q32. A trace records (waiting consumers awakened by WakeAll, consumers that find no item): (1,0), (2,1), (4,3), (8,7), (16,15). If one item is available and all awakened consumers compete, how many of eight awakened consumers find no item?

A.Eight
B.One
C.Zero
D.Seven ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: One consumer removes the single available item, leaving seven awakened consumers with a false predicate. They must return to waiting, illustrating the unnecessary wakeups created when a broadcast is larger than the available work.

Q33. A producer uses an auto-reset event for a queue. The trace gives (time, queued items, event state): (0,0,nonsignaled), (1,1,signaled), (2,3,signaled), (3,2,nonsignaled), (4,2,nonsignaled). Which observation identifies the flaw?

A.At time 1, the queue has one item and the event is signaled
B.At time 2, three items are queued while the event is signaled
C.At time 0, both the queue and event are empty or nonsignaled
D.At time 3, two items remain queued although the event is nonsignaled ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The trace shows two queued items at time three while the auto-reset event is nonsignaled. A consumer can therefore remain asleep despite pending work, because one event state does not count every queued item.

Q34. WaitForMultipleObjects is called with bWaitAll set to FALSE and handles ordered as [event A, semaphore B, mutex C]. Event A is nonsignaled, while B and C are signaled. Which result is expected?

A.The call waits until all three objects are signaled
B.The call reports the first signaled handle in array order, semaphore B, and consumes one semaphore permit ✅
C.The call always reports the mutex because mutexes have priority
D.The call reports event A because it is first in the array even though it is nonsignaled
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In wait-any mode, Windows checks handles in array order and returns the index of the first signaled object. Because B is the first signaled handle, its semaphore count is decremented as the wait succeeds.

Q35. A Windows UI thread owns windows and waits indefinitely with WaitForMultipleObjects while it must also process system messages. What is the safer design direction?

A.Keep the infinite wait and stop processing messages
B.Replace every wait with Sleep(0)
C.Use a message-aware wait such as MsgWaitForMultipleObjects so the thread can also respond to queued input ✅
D.Increase the number of mutexes until messages are delivered
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A thread that owns windows must continue processing messages. A message-aware wait can unblock for synchronization objects or queued input, avoiding deadlock risks caused by an infinite wait that prevents required message processing.

Q36. Two separate Windows processes share a bounded queue of five records. They need to prevent simultaneous queue updates, count free slots, and count available records. Which design assigns the correct role to each primitive?

A.Use one manual-reset event for mutual exclusion and one critical section shared across both processes
B.Use an auto-reset event as the five-slot counter and volatile flags to protect the queue
C.Use one InterlockedIncrement call to protect the queue and represent both resource counts
D.Use a named mutex for exclusive queue updates and named semaphores initialized to five free slots and zero available records ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The named mutex coordinates exclusive access across processes. Separate semaphores track free capacity and queued records: five and zero initially. Each successful insertion and removal must update the corresponding permit counts consistently.

🔗 Related Topics (MCQs)