๐ Thread synchronization in Process management in Window 7 (8 MCQs)
Coordinating Concurrent Windows Threads
Thread synchronisation in Windows 7 coordinates access to shared data and resources among concurrent threads. Windows provides critical sections, mutexes, semaphores, events, condition variables, and interlocked operations. These mechanisms establish mutual exclusion, notification, or ordering so multiple threads can cooperate without corrupting shared state or violating application invariants.
Why Shared Memory Creates Race Conditions
Threads within one process share memory, so simultaneous access to mutable variables can produce lost updates or inconsistent data. Processor scheduling and multicore execution make operation ordering unpredictable. Synchronisation primitives establish rules for entering critical sections and communicating when a resource or condition becomes available.
Mutexes, Events and Interlocked Operations
A mutex grants ownership to one thread at a time and can coordinate across processes. A critical section provides efficient process-local mutual exclusion. Semaphores manage counts of available resources, events signal conditions, and interlocked operations provide atomic updates for supported variables.
Example of Protecting a Shared Queue
Two worker threads access a shared queue. Thread A locks a critical section, removes one item, and unlocks it. Thread B must wait before changing the same queue. This prevents concurrent updates from corrupting the queue's linked structure or losing items.
Correctness, Contention and Deadlock
Synchronisation preserves data integrity and supports safe parallel execution. Locks introduce waiting and can reduce throughput under contention. Inconsistent lock order can produce deadlock, while holding a lock during slow I/O can block unrelated work. Correct design requires minimal critical sections and clear ownership rules.
Misconceptions About Thread Synchronisation
'An event provides mutual exclusion' is false because it signals a condition. 'A mutex can be released safely by any thread' ignores ownership rules. 'Interlocked operations make an entire multi-step algorithm atomic' is incorrect because only the supported operation is indivisible.
Exam Focus: Selecting Windows Thread Primitives
Compare mutexes, critical sections, semaphores, events, and interlocked operations by their functions. Identify race conditions in shared counter or queue examples. Questions may ask which primitive provides mutual exclusion, which supports notification, or how lock ordering causes deadlock.
Key Terms of Windows Thread Synchronisation
- Mutex - Ownership-based mutual exclusion object.
- Critical section - Process-local locking mechanism.
- Semaphore - Counter controlling resource availability.
- Event - Object signalling a condition.
- Interlocked operation - Atomic update of shared data.
๐ All Thread synchronization in Process management in Window 7 MCQs
Q1. What does APC stand for in Windows operating systems?
๐ Explanation: The correct answer is Asynchronous Procedure Call because APCs are a mechanism for queuing procedures to execute in the context of a specific thread. Option B invents a term that does not exist in Windows. Option C and D describe unrelated concepts. Understanding the acronym helps identify the purpose of APCs, which is to allow deferred execution of code, often for I/O completion or thread management.
Q2. Why are userโmode APCs only delivered when a thread is in an alertable wait state?
๐ Explanation: Userโmode APCs are delivered only when a thread is alertable because this guarantees the thread is in a safe point to run additional code without corrupting its state. Option A is false; the kernel can interrupt user code but chooses not to for APCs. Option C misstates the timing requirement, and Option D confuses APC delivery with I/O priority. The alertable state provides a controlled environment for APC execution.
Q3. A driver queues a DPC that takes 30โฏms to complete. The system's quantum is 15โฏms. Which effect is most likely?
๐ Explanation: The DPC runs at a priority lower than device ISR but higher than normal threads, so while it executes it prevents other threads from being scheduled on that processor. Because the DPC exceeds the quantum, it occupies the CPU longer than a thread would, delaying subsequent DPCs and increasing I/O latency. Option A ignores the scheduling impact, Option C mischaracterizes DPC behavior, and Option D incorrectly suggests ISR blockage.
Q4. How does the priority of a DPC compare to the priority of normal threads and device ISR?
๐ Explanation: DPCs are designed to run after the ISR has finished, so they have a lower priority than the ISR but a higher priority than normal thread execution. This ordering ensures critical interrupt handling occurs first, while DPCs handle less urgent work without preempting regular threads. Option A reverses the relationship, Option C incorrectly states equal priority, and Option D suggests no relationship, which is inaccurate for the Windows scheduling model.
Q5. A system experiences high CPU usage due to many DPCs. Which mitigation strategy is most appropriate?
๐ Explanation: Moving lengthy operations out of DPCs into worker threads prevents DPCs from monopolizing the CPU, reducing latency and keeping interrupt handling responsive. Increasing worker threads (Option A) does not address the root cause, raising the quantum (Option B) affects thread scheduling but not DPC execution, and disabling APCs (Option D) removes a useful mechanism unrelated to DPC overload.
Q6. An application initiates an asynchronous I/O operation and then calls SleepEx(0, TRUE). What is the purpose of the TRUE flag?
๐ Explanation: The TRUE flag makes the sleep alertable, meaning the thread can receive and execute queued APCs during the wait. This is essential for handling completion of asynchronous I/O without busyโwaiting. Option A describes the opposite behavior, Option C incorrectly suggests I/O blocking, and Option D misinterprets the flag as a termination signal. Alertable sleeps enable efficient APC processing.
Q7. What is the main reason the dispatcher maintains a pool of worker threads for ISR and DPC work items?
๐ Explanation: Worker threads give the dispatcher a place to run work items that are too timeโconsuming for ISR or DPC contexts, ensuring that interrupt processing remains fast and responsive. Option A addresses a different synchronization issue, Option C is false because ISR speed is unchanged, and Option D misrepresents the separation between user and kernel modes.
Q8. A developer mistakenly queues a DPC that accesses pageable memory. What potential problem can arise?
๐ Explanation: DPCs run at elevated IRQL where paging is not allowed; accessing pageable memory can cause a page fault, which the kernel cannot handle at that level, potentially resulting in a bug check (system crash). Option A is opposite of the likely slowdown, Option C incorrectly suggests the DPC is dropped, and Option D misattributes the delay to the ISR rather than the DPC's illegal memory access.