📝 Fibers in Process management in Window 7 (6 MCQs)
User Mode Scheduled Execution Units
Fibers are lightweight execution units in Windows that allow an application to manage scheduling in user mode. Multiple fibers can run within a thread, sharing the thread's process resources while maintaining separate stacks and execution contexts. Unlike ordinary kernel-scheduled threads, fibers are cooperatively scheduled by application code rather than selected independently by the Windows kernel scheduler.
Why Applications May Need Cooperative Scheduling
Some applications require precise control over when execution switches between tasks, such as specialised servers or language runtimes. Kernel thread scheduling introduces system-level decisions and context-switching overhead. Fibers allow an application to organise cooperative execution, but a fiber that fails to yield can prevent other fibers on the same thread from running.
Converting Threads and Switching Fibers
A thread can be converted into a fiber using ConvertThreadToFiber, after which it can create additional fibers. SwitchToFiber transfers execution to another fiber within the process. Fiber state includes its own stack and saved execution context, while the kernel continues scheduling the underlying thread.
Example of Two Cooperative Fibers
A thread hosts fibers A and B. Fiber A processes a batch of records and calls SwitchToFiber when it reaches a safe point. Fiber B then runs its task and later switches back. Neither fiber runs simultaneously with the other on that single underlying thread.
Low Overhead and Cooperative Scheduling Limits
Fibers can reduce kernel scheduling involvement and give applications explicit control over task switching. They require cooperative programming and careful management of execution state. A blocking system call can stall the underlying thread and every fiber assigned to it, making fibers unsuitable where independent pre-emption is required.
Misconceptions About Windows Fibers
'A fiber is scheduled independently by the kernel' is false because its host thread is scheduled. 'Fibers execute in parallel on one thread' ignores their cooperative switching. 'A fiber cannot block' is incorrect because blocking operations can suspend the entire underlying thread.
Exam Focus: Threads Versus Fibers
Compare fibers and threads by scheduling authority, execution state, and concurrency. Trace ConvertThreadToFiber and SwitchToFiber behaviour. Questions may ask why a non-yielding fiber delays other fibers or explain why a fiber-based design needs cooperative task boundaries.
Key Terms of Windows Fibers
- Fiber - User-mode scheduled execution unit.
- ConvertThreadToFiber - Converts a thread into a fiber host.
- SwitchToFiber - Transfers execution to another fiber.
- Cooperative scheduling - Tasks yield control voluntarily.
- Fiber stack - Private stack for a fiber.
📝 All Fibers in Process management in Window 7 MCQs
Q1. What does APC stand for in Windows kernel terminology?
📖 Explanation: The correct answer is Asynchronous Procedure Call because APCs are kernel objects that allow code to run in the context of a specific thread. Option A misstates the word Process, Option B mixes unrelated terms, and Option D suggests an application‑level concept that does not exist in this context. Knowing the exact expansion helps identify the purpose of APCs when designing thread‑aware code.
Q2. Why does the system schedule a DPC at a priority lower than device ISR but higher than normal thread execution?
📖 Explanation: The correct answer is that DPCs run at a priority that lets them finish pending interrupt work without delaying normal thread scheduling. Option A is partly true but not the primary reason; Option B is inaccurate because DPCs are not required to finish before the next ISR; Option D reverses the priority order. Understanding this hierarchy explains how Windows balances responsiveness and throughput.
Q3. A driver’s ISR has completed the urgent hardware handling and now needs to perform additional processing that may take several milliseconds. Which mechanism should the driver use?
📖 Explanation: The correct answer is a DPC because it is designed to defer non‑urgent work after an ISR while still running at a high priority. APCs cannot be queued from an ISR and require an alertable thread, making them unsuitable. Creating a new thread would add unnecessary overhead, and a timer would introduce extra delay. Selecting DPC ensures timely processing without blocking critical interrupt handling.
Q4. In which situation will an APC be executed in user mode?
📖 Explanation: The correct answer is that APCs run only when a thread is waiting in the kernel and marked alertable, because this state allows the kernel to safely inject user‑mode code. Option A is wrong because a non‑alertable wait blocks APCs. Option B is incorrect because APCs are not delivered during normal execution. Option C misstates the condition. Recognizing this rule is crucial for correctly synchronizing asynchronous I/O notifications.
Q5. A system experiences heavy I/O traffic and must minimize latency for thread scheduling while still handling timer expirations. Which combination best meets these goals?
📖 Explanation: The correct answer pairs DPCs for quick timer handling with worker threads for longer tasks, preserving low latency for thread scheduling. Option A would overload worker threads and increase delay. Option C places too much work in the ISR, violating design rules. Option D eliminates DPCs, removing an efficient mechanism for timely processing. This combination reflects how Windows balances responsiveness and workload distribution.
Q6. When a periodic timer expires, why does Windows typically use a DPC to process the expiration rather than a regular thread?
📖 Explanation: The correct answer is that DPCs avoid the overhead of creating or waking a full thread and execute before normal user‑mode scheduling, providing a fast response to timer events. Option A is partially true but not the main benefit; Option B is inaccurate because the ISR has already completed; Option D is false because DPCs are not bound to a specific processor. Understanding this choice shows why DPCs are preferred for time‑critical callbacks.