📝 Threads and scheduling in Windows 7 (13 MCQs)
Thread Based Execution in Windows 7
Windows 7 uses threads as the basic units of execution and scheduling. A process provides a virtual address space and resource context, while each thread has its own execution state, stack, and scheduling information. The kernel scheduler allocates processor time to runnable threads using priorities, pre-emption, and time quanta across available processors.
Why Threads Separate Resource Ownership from Execution
A process may perform several tasks concurrently, such as user interaction, file access, and background computation. A single execution path would force unrelated work to wait. Threads share selected process resources while maintaining separate execution contexts, allowing concurrency and parallelism on multiprocessor systems.
Thread States and Priority Based Scheduling
Windows threads move among states such as ready, running, waiting, and terminated. The scheduler selects the highest-priority ready thread for an available processor. Threads may be pre-empted when higher-priority work becomes ready or when a scheduling quantum expires, while waiting threads become ready after an event or resource becomes available.
Example of a Multithreaded Application
A text editor uses one thread for the interface and another for file saving. When the saving thread waits for disk I/O, the interface thread can continue responding to user input. On a multicore processor, both threads may execute simultaneously if suitable processors are available.
Responsiveness, Priorities and Contention
Thread scheduling supports responsive applications and parallel workloads. Priority boosts can improve response after selected events, but inappropriate priorities may delay other work. Synchronisation around shared data introduces contention, and excessive threads increase memory and scheduling overhead. Performance depends on workload, processor count, and the balance of runnable and waiting threads.
Misconceptions About Windows Thread Scheduling
'Windows schedules processes as indivisible execution units' is false because threads are scheduled. 'Every thread receives exactly the same CPU time' ignores priority and scheduling policy. 'A waiting thread can be pre-empted from a CPU' is incorrect because it is already not executing.
Exam Focus: Thread States and Pre-emptive Scheduling
Identify thread states and explain transitions caused by pre-emption, blocking, and event signalling. Distinguish process resources from thread execution context. Questions may examine priority levels, quantum expiration, context switching, and how multiple threads use available processors concurrently.
Key Terms of Windows Threads and Scheduling
- Thread - Basic schedulable execution unit.
- Process - Resource and address-space container.
- Ready state - Eligible for processor execution.
- Pre-emption - Interrupting execution to run another thread.
- Quantum - Allocated scheduling time interval.
📝 All Threads and scheduling in Windows 7 MCQs
Q1. What is the main function of the Hardware Abstraction Layer (HAL) in Windows?
📖 Explanation: The HAL's purpose is to present a uniform virtual hardware interface, so upper‑level components do not need to know the exact chipset details. Option B states this directly. Options A, C, and D describe unrelated functions: a GUI, networking, and file‑system management, which are handled by other subsystems. By abstracting hardware, the HAL allows a single driver version per CPU architecture, simplifying development and improving portability.
Q2. Why does Windows employ an object‑oriented design for its kernel components?
📖 Explanation: Object‑oriented design groups related data (attributes) and functions (methods) into objects, making kernel code modular and easier to maintain. Option A captures this benefit. Option B is inaccurate because the kernel still uses assembly only where necessary. Option C mischaracterizes the design philosophy, and option D ignores the essential role of synchronization in a concurrent kernel environment.
Q3. How does thread scheduling interact with interrupt handling in the Windows kernel?
📖 Explanation: The kernel separates interrupt handling from thread scheduling; interrupts are serviced in kernel mode, but they do not depend on thread completion. Option C correctly notes that interrupt handling occurs in kernel mode, not user mode, and is independent of the scheduler’s decisions. Option A is false because threads rarely run to completion before an interrupt. Option B misstates that the scheduler directly preempts threads for interrupts; the interrupt handler runs immediately. Option D is incorrect because the kernel does not disable scheduling entirely during an interrupt.
Q4. A program creates Thread X with priority 8 and Thread Y with priority 4. Both become ready at the same time on a dual‑core system. Which statement best describes their execution?
📖 Explanation: Windows can schedule ready threads on any idle core, so Thread X and Thread Y may execute concurrently on different CPUs. However, if they contend for the same core, the scheduler prefers the higher‑priority thread, which is Thread X. Option D captures both possibilities. Option A ignores priority, Option B reverses the priority order, and Option C suggests mandatory preemption even when separate cores are available, which is not required.
Q5. In a priority‑inversion scenario where a low‑priority thread holds a mutex needed by a high‑priority thread, which kernel mechanism can prevent the high‑priority thread from being blocked indefinitely?
📖 Explanation: Priority inheritance temporarily raises the low‑priority thread’s priority to match that of the waiting high‑priority thread, allowing it to release the mutex promptly. Option A describes this mechanism. Round‑robin scheduling (B) and time slicing (C) manage CPU allocation but do not resolve inversion. Thread termination (D) would abort the low‑priority thread but is not a normal solution and would cause data loss.
Q6. Which responsibility of the Windows kernel involves low‑level processor synchronization?
📖 Explanation: Low‑level synchronization ensures that multiple processors or cores can safely access shared data structures, typically using spin locks, interlocked functions, or other atomic primitives. Option B correctly identifies this role. Memory allocation (A) is a higher‑level service, GUI rendering (C) belongs to the user‑mode subsystem, and network sockets (D) are provided by the networking stack, not by low‑level synchronization.
Q7. When a user‑mode application calls a system service, what happens during the transition to kernel mode?
📖 Explanation: During a system call, the CPU performs a mode switch, saving the user‑mode context, validating parameters, and then executing the requested kernel routine. Option B describes this process. Changing CPU frequency (A) is unrelated, terminating the thread (C) is not the normal flow, and clearing registers leading to a reboot (D) is incorrect.
Q8. Why is only one version of each device driver required for a given CPU architecture in Windows?
📖 Explanation: The HAL presents a uniform virtual hardware interface, so drivers can interact with devices without needing to know the exact chipset implementation. Option A explains this abstraction. Option B is false; Windows supports many hardware variations. Option C misstates that drivers are universal without HAL support. Option D suggests dynamic code rewriting, which does not occur.
Q9. A system uses preemptive multitasking with a time slice of 20 ms. If a CPU‑bound thread runs for 45 ms, how many times will the scheduler preempt it?
📖 Explanation: The scheduler allocates 20 ms slices. After the first 20 ms, it preempts the thread (first preemption). After the second 20 ms, it preempts again (second preemption). The remaining 5 ms runs to completion without another preemption. Thus, two preemptions occur, making option C correct. Option A ignores slicing, option B counts only one preemption, and option D incorrectly adds an extra preemption.
Q10. A developer binds a high‑priority thread to CPU 0 using thread affinity. What is a likely consequence if CPU 0 becomes overloaded with low‑priority work?
📖 Explanation: Thread affinity restricts a thread to a specific processor, so the high‑priority thread cannot move even if the CPU is busy with lower‑priority work, leading to possible latency. Option B captures this effect. Option A is false because affinity prevents migration. Option C misinterprets priority inheritance, and option D describes behavior that the scheduler does not perform.
Q11. When the Windows API function SetThreadPriority is used to raise a thread's priority, which outcome is most likely?
📖 Explanation: Increasing a thread's priority makes the scheduler favor it, but it will only run ahead of other threads if those threads have lower or equal priority and are not already running. Option B reflects this behavior. Option A overstates the effect, option C is incorrect because the change takes effect immediately, and option D misrepresents CPU allocation.
Q12. In Windows kernel terminology, what distinguishes an object type from an object instance?
📖 Explanation: The kernel defines object types as templates describing attributes and methods; each created object (instance) holds specific values for those attributes. Option C correctly states this relationship. Option A reverses the concepts, option B is partially correct but mislabels where they exist, and option D denies the meaningful distinction that the kernel makes.
Q13. Why is the Windows kernel primarily written in C with only limited assembly code?
📖 Explanation: C offers constructs for pointer arithmetic and system calls, giving sufficient control over hardware while remaining portable across CPU families. Assembly is reserved for tasks that require exact timing or privileged instructions. Option B captures this rationale. Option A overstates C's capabilities, option C is false because assembly is still used for critical sections, and option D incorrectly claims C is always faster than assembly.