📝 Interprocess communication using Windows 7 messaging (8 MCQs)
Message Based Communication Between Windows Processes
Windows 7 supports interprocess communication through message mechanisms that allow applications to exchange notifications and data without directly accessing another process's private memory. Windows messaging uses message queues associated with GUI threads, while other IPC facilities include named pipes, mailslots, shared memory, sockets, and remote procedure calls.
Why Process Isolation Requires Explicit Communication
Separate process address spaces prevent ordinary direct memory access between applications. Applications still need to notify one another, exchange commands, and coordinate work. Message-based interfaces provide controlled communication, but message delivery and data transfer must account for thread responsiveness, permissions, and possible delays.
PostMessage, SendMessage and Message Queues
Windows GUI threads maintain message queues for input and application messages. PostMessage places a message in the target thread's queue and returns without waiting for processing. SendMessage normally waits for the target window procedure to process the message. WM_COPYDATA can carry data between cooperating applications through message handling.
Example of Sending a Data Notification
An application posts a custom message to another application's window to indicate that a background operation has finished. The receiving GUI thread retrieves the message from its queue and handles it in its window procedure. If actual data must be transferred, a shared-memory or other IPC mechanism may be more suitable.
Responsiveness and Message Security
Windows messaging is convenient for GUI coordination and notification. Synchronous SendMessage can block the sender while the recipient processes a message, potentially causing responsiveness problems. Cross-process messaging also requires care because window messages are not a general secure transport for arbitrary large data.
Misconceptions About Windows Messaging
'PostMessage waits until the receiver processes the message' is false because it queues and returns. 'SendMessage always returns immediately' ignores synchronous processing. 'A window message automatically copies an unlimited data structure between processes' is incorrect because payload size and pointer validity are constrained by process boundaries and message rules.
Exam Focus: Message Queues and IPC Alternatives
Compare PostMessage and SendMessage by waiting behaviour. Explain how GUI message queues support interprocess notifications and when WM_COPYDATA or shared memory may be used. Questions may compare window messaging with named pipes, mailslots, sockets, or RPC by communication pattern and data capacity.
Key Terms of Windows Messaging
- Window message - Notification processed by a window procedure.
- Message queue - Stores pending thread messages.
- PostMessage - Queues a message asynchronously.
- SendMessage - Sends a message synchronously.
- WM_COPYDATA - Message for transferring selected data between applications.
📝 All Interprocess communication using Windows 7 messaging MCQs
Q1. What does the abbreviation APC stand for in Windows kernel terminology?
📖 Explanation: The correct answer is Asynchronous Procedure Call. APCs are kernel mechanisms that allow code to be executed in the context of a specific thread when that thread enters an alertable wait state. The other choices are fabricated terms that do not appear in Windows documentation. Automatic Process Control, Advanced Priority Context, and Atomic Process Communication are unrelated concepts. Understanding this definition is essential because APCs are a core part of inter‑thread communication and I/O completion notifications.
Q2. Why are user‑mode APCs delivered only when a thread is in an alertable wait state rather than at any arbitrary point in execution?
📖 Explanation: The correct answer is that the kernel can safely switch to user code only during alertable waits. APCs are queued to a specific thread, but they are executed only when that thread signals that it is ready to run user‑mode code without risking corruption. The other options are incorrect: the stack is not locked by alertable waits, APCs do not require the thread to be suspended, and alertable waits do not affect CPU priority. This behavior ensures safe inter‑process communication.
Q3. A driver receives a hardware timer interrupt and queues a DPC to handle the timer expiration. Which of the following best describes the order in which the ISR, DPC, and normal thread execution will occur?
📖 Explanation: The correct sequence is ISR → DPC → normal thread. When the timer fires, the interrupt service routine (ISR) runs at the highest priority to acknowledge the hardware event, then it schedules a deferred procedure call (DPC) to perform the less‑time‑critical work. After the DPC finishes, normal thread scheduling resumes. Option A places the normal thread before the DPC, which is wrong because DPCs run before returning to regular thread execution. Options C and D invert the ISR and DPC order, contradicting the designed priority hierarchy.
Q4. How does the priority relationship between DPCs, ISRs, and regular threads influence overall system responsiveness?
📖 Explanation: The correct answer is that DPCs run at lower priority than ISRs but higher than normal threads. This arrangement lets the ISR quickly clear the hardware interrupt, then schedules a DPC to finish the remaining work without delaying other critical interrupts. Because DPCs outrank regular threads, they get CPU time promptly, preserving responsiveness. Option A incorrectly suggests DPCs outrank ISRs, which would interfere with interrupt handling. Option C makes DPCs indistinguishable from normal threads, reducing latency guarantees. Option D places DPCs at the lowest priority, which would cause unnecessary delays.
Q5. A driver decides to queue a work item to a worker thread instead of using a DPC for a non‑time‑critical cleanup task. What is the most likely effect of this decision?
📖 Explanation: The correct answer is that the task will run at normal thread priority, possibly delaying its completion but freeing the DPC queue. Worker threads are scheduled like any other thread, so the cleanup work will not pre‑empt higher‑priority code and will not block the DPC mechanism. Option A is false because worker threads do not pre‑empt other threads. Option C is incorrect; queued work items persist across reboots. Option D is inaccurate—worker threads can safely access kernel memory when designed properly. This choice demonstrates proper use of deferred work for non‑urgent operations.
Q6. Why are DPC routines prohibited from accessing pageable memory, and what could happen if this rule is violated?
📖 Explanation: The correct answer is that accessing pageable memory may cause a page fault at DISPATCH_LEVEL, which can crash the system. DPCs run at elevated IRQL (DISPATCH_LEVEL) where page faults cannot be serviced, so any attempt to touch pageable pages triggers a fatal error. Option B is wrong because encryption is not the issue. Option C misstates that swapping is safe; it is not allowed at that IRQL. Option D is incorrect because the restriction is enforced at runtime, not at compile time. This rule ensures stability in high‑priority deferred processing.
Q7. If a thread frequently enters an alertable state and a heavy‑weight APC is queued to it, which impact is most likely on overall system latency?
📖 Explanation: The correct answer is that latency may increase because the thread spends time executing the heavy‑weight APC rather than performing its usual work. APCs execute whenever the thread is in an alertable wait, so a large APC can consume CPU cycles and delay other tasks, raising overall system latency. Option A is incorrect; APCs do not inherently speed up scheduling. Option C is false because APCs execute on the same thread, not a separate core. Option D mischaracterizes APC behavior; they do not cause random context switches beyond the intended alertable wait. Understanding this helps developers avoid performance pitfalls.
Q8. A background worker thread needs to notify the main UI thread of progress using a custom Windows message. Which method ensures safe delivery without risking race conditions?
📖 Explanation: The correct answer is to post the message with PostMessage to the UI thread’s handle. PostMessage queues the message safely to the UI thread’s message queue, allowing the UI thread to process it in its normal message loop, which avoids race conditions. Option A (SendMessage) would block the worker thread and execute the handler on the worker’s context, potentially causing deadlocks. Option C introduces shared‑state polling, which is error‑prone. Option D is nonsensical; raising an exception in another thread is not a valid communication mechanism. This approach aligns with Windows messaging best practices for inter‑thread communication.