📝 Thread Pools in operating system (33 MCQs)
Preallocated Worker Threads and Task Execution
A thread pool is a group of reusable worker threads maintained to execute submitted tasks. It belongs to application and runtime concurrency management and reduces the need to create a new thread for every incoming request. Workers wait for available tasks, execute assigned work, and return to an available state. The pool controls concurrency through a configured or dynamically adjusted number of worker threads.
Why Repeated Thread Creation Creates Overhead
Applications such as web servers may receive thousands of short requests. Creating and terminating a new thread for each request consumes memory and processor time. Unrestricted thread creation can also overwhelm system resources. A thread pool addresses these problems by reusing existing workers and limiting the number of simultaneously executing tasks.
Task Queues, Worker Allocation, and Completion
When a task arrives, the application submits it to a pool-managed queue. An available worker removes the task, executes it, and reports or stores the result. After completion, the worker returns to the available pool. If every worker is busy, additional tasks wait in the queue until capacity becomes available.
Serving Requests with a Five-Thread Pool
Consider a web server using five worker threads and receiving eight requests simultaneously. Five workers begin processing requests, while the remaining three wait in the task queue. When one worker completes its request, it retrieves the next waiting task. This arrangement limits active worker execution while supporting reuse of existing threads.
Throughput, Queueing Delays, and Pool Capacity
Thread pools reduce creation overhead and prevent unbounded thread growth, improving resource control in servers and background-processing systems. However, a pool that is too small creates queueing delays, while an excessively large pool increases memory use and context switching. Blocking tasks can occupy workers for long periods, reducing the capacity available for new work.
Misconceptions About Reusable Worker Threads
'A thread pool creates a new thread for every request' is incorrect because its primary purpose is worker reuse. 'A fixed pool guarantees that every task starts immediately' is incorrect because tasks may wait in a queue. 'Increasing pool size always increases throughput' is incorrect because CPU, memory, and I/O resources impose limits.
Exam Focus: Worker Counts and Task Queue Behaviour
Trace task submission, queueing, worker allocation, completion, and worker reuse. Given five workers and eight simultaneous tasks, identify how many begin immediately and how many initially wait. Questions may examine pool sizing, queue limits, blocked workers, resource exhaustion, and the relationship between thread pools and implicit threading.
Key Terms of Thread Pools
- Thread pool - Reusable collection of worker threads.
- Worker - Thread executing an assigned task.
- Task queue - Stores pending work.
- Pool size - Number of available worker threads.
- Queueing delay - Time spent awaiting execution.
- Worker reuse - Executing multiple tasks with one thread.
📝 All Thread Pools in operating system MCQs
Q1. A web server creates a new operating-system thread for every request. During traffic spikes, thread creation and destruction consume significant resources. Which redesign most directly addresses this problem?
📖 Explanation: A thread pool reuses existing workers across multiple tasks, avoiding repeated creation and destruction. A bounded pool also limits concurrent thread resources, helping the server handle bursts without allowing thread count to grow without control.
Q2. What does a conventional worker thread do after completing a task obtained from a pool queue?
📖 Explanation: A worker usually remains alive after completing its assigned task. It returns to the pool, waits for more work, and retrieves another queued task when available, amortizing thread creation costs across multiple submissions.
Q3. A pool has eight workers and receives 100 runnable tasks. All workers are busy. What normally happens to the other tasks in a conventional queued pool?
📖 Explanation: A conventional pool queues tasks when all workers are occupied. As each worker finishes its current task, it retrieves another task from the queue, so submitted work can exceed the number of available worker threads.
Q4. A pool uses a FIFO task queue and three workers. Task A is removed first but takes 20 ms, while tasks B and C each take 2 ms. Which statement is generally correct?
📖 Explanation: FIFO generally determines task removal order, not completion order across concurrent workers. B and C may finish before A because their execution durations are shorter, even when A was removed from the queue first.
Q5. Two servers perform the same tasks. One creates a new thread for every task; the other reuses a fixed pool. Their task execution times are similar. Why may the pooled server still have lower total response time?
📖 Explanation: Similar task execution times do not imply equal total response times. Reusing workers avoids repeated setup and teardown costs, although queue waiting, scheduling, synchronization, and the task's actual execution time still matter.
Q6. A service configures a fixed pool with a maximum of 12 workers. Under heavy load, 40 tasks are submitted. Which statement about the worker count is correct?
📖 Explanation: A fixed pool with a maximum of twelve workers limits its worker population to that configured capacity. Excess submitted tasks must wait, be rejected, or follow another defined policy rather than increasing the worker count beyond the limit.
Q7. A pool has a maximum of eight workers and a queue capacity of twenty tasks. Eight tasks are running and twenty are queued. Five additional tasks arrive, and the configured policy rejects submissions when the queue is full. What should happen?
📖 Explanation: All eight workers are occupied and all twenty queue positions are full. Under the stated rejection policy, the five new submissions cannot be accepted and must be rejected or handled through an explicitly configured alternative.
Q8. A service uses a bounded pool and a bounded task queue. During a traffic burst, requests arrive faster than workers can complete them. What is the principal system-level benefit of the limits?
📖 Explanation: Bounded workers and queues constrain resource consumption when arrivals exceed service capacity. Requests may wait or be rejected, but explicit overload handling is safer than allowing threads and queued work to grow without limit.
Q9. A workload consists of independent CPU-bound tasks that do not block. The server has eight effective CPU cores. Which initial worker-pool size is a reasonable baseline for experiments?
📖 Explanation: For CPU-bound tasks that remain runnable, a starting pool size near the number of effective cores avoids excessive oversubscription. Measurement is still necessary because scheduling, memory behavior, and other system activity influence the best size.
Q10. A service receives 500 tasks per second. Each task occupies a worker for an average of 0.02 seconds. Ignoring bursts and overhead, approximately how many workers are needed to match the average offered workload?
📖 Explanation: Average worker demand is arrival rate multiplied by worker occupancy: worker-seconds per second. Ten workers approximately match the average offered workload, although bursts and variability may require additional capacity.
Q11. A pool is used for many tasks that spend most of their time waiting for network or storage responses. Why might a pool larger than the number of CPU cores be useful?
📖 Explanation: I/O-bound tasks can occupy workers while waiting for external events. A larger pool may keep processors productive by allowing other tasks to run, but excessive workers consume memory and can increase contention, so measurement remains essential.
Q12. A four-worker pool runs a mix of short database queries and long file conversions. When conversions begin, query latency rises sharply. Which change most directly addresses the likely cause?
📖 Explanation: Long or blocking conversions can occupy all workers, leaving short queries queued. Separate pools isolate the workloads and allow independent capacity choices, reducing interference without requiring unlimited threads or uncontrolled resource consumption.
Q13. A dynamically growing pool responds quickly during bursts but uses substantially more memory than a fixed pool. What is the best way to choose between them?
📖 Explanation: Dynamic growth can improve responsiveness when fixed capacity is insufficient, but it consumes additional resources and may increase contention. A sound choice measures latency, throughput, memory, and scheduling costs against the service's workload and objectives.
Q14. A pool has six workers. Six tasks each wait synchronously for a network response lasting eight seconds. Another short task arrives one second later. Assuming all workers remain occupied, when can the short task begin?
📖 Explanation: Each blocking task continues occupying its worker while waiting for the network response. Since all six workers are unavailable, the short task must wait until a worker becomes free, unless the implementation supplies additional execution capacity.
Q15. A fixed pool contains four workers. Each running task waits synchronously for a fifth task queued in the same pool, and the fifth task is needed for all four tasks to finish. What is the principal risk?
📖 Explanation: All four workers are occupied by tasks waiting for a dependent task that cannot start. The pool has no free worker to execute that dependency, creating thread-starvation deadlock; nonblocking composition or separate capacity can avoid it.
Q16. A team observes that a shared task queue is protected by one mutex. Increasing workers from four to sixty-four raises lock contention but barely improves throughput. What is the most likely bottleneck?
📖 Explanation: A single shared queue can serialize task acquisition when many workers compete for its mutex. More workers then increase contention without proportional useful work, so profiling and scalable queue designs may be appropriate.
Q17. A pool's workers retrieve tasks from a shared queue. A programmer assumes that the thread-safe queue makes every task's shared data safe automatically. What is the flaw?
📖 Explanation: A thread-safe queue protects its own internal operations and task transfer. Tasks can still access shared variables concurrently, so their data needs appropriate synchronization, atomic operations, or immutability to avoid races.
Q18. A pool has tasks A, B, and C in a FIFO queue. Two workers become available almost simultaneously. Which ordering guarantee is safest to assume without additional coordination?
📖 Explanation: A FIFO queue may provide submission-order removal, but multiple workers execute tasks concurrently. Different task durations and scheduling can change start or completion order, so strict completion ordering requires additional coordination.
Q19. A worker task fails because of invalid input. The pool framework's exception behavior is not documented. What should a robust application do?
📖 Explanation: Executing a task does not guarantee successful completion. Pool frameworks may capture, propagate, log, or expose failures through task results, so applications should define recovery behavior and verify the specific implementation's error semantics.
Q20. A service must shut down while a pool contains queued and running tasks. Which policy best supports graceful termination?
📖 Explanation: Graceful shutdown normally rejects new submissions and gives accepted tasks an opportunity to complete, subject to a defined timeout or cancellation policy. This avoids unnecessary loss of work and reduces the risk of leaving resources inconsistent.
Q21. A pool has four workers. Task A submits task B to the same pool and waits synchronously for B's result. All four workers behave similarly. What can happen?
📖 Explanation: When every worker blocks waiting for dependent tasks queued in the same fixed pool, no worker remains to execute those tasks. This can cause thread-starvation deadlock; nonblocking task composition avoids occupying workers while waiting.
Q22. A web service uses a bounded pool. During overload, submissions are rejected, but callers receive no notification. Which operational improvement is most important?
📖 Explanation: A bounded pool protects resources by rejecting work when capacity is exhausted. Without reporting, callers cannot respond appropriately; explicit errors, metrics, and controlled retries or backpressure help the service manage overload safely.
Q23. A worker finishes task T1 and immediately obtains T2 from the queue. Which advantage does this reuse provide?
📖 Explanation: The worker remains available after T1 completes and can execute T2 without creating another thread. Reuse amortizes lifecycle costs across tasks, although each task still requires execution time and any necessary synchronization.
Q24. A database allows at most five concurrent connections, but an application pool has eight workers. All eight workers request a connection at once and wait synchronously if none is available. What is a likely consequence?
📖 Explanation: The database permits only five concurrent connections, so at least three requests cannot acquire one immediately. Those workers may remain occupied while waiting, reducing useful pool capacity and increasing latency for other tasks.
Q25. A pool has a maximum of eight workers and a queue capacity of twenty tasks. Eight tasks are running and fifteen are queued. Three new tasks arrive simultaneously. Under a reject-on-full policy, how many can be accepted into the queue?
📖 Explanation: The queue has capacity for twenty tasks and currently contains fifteen, leaving five available positions. All three new tasks fit, so the pool can accept three without exceeding its configured queue limit.
Q26. A service receives tasks in bursts. Its fixed pool has four workers, while its queue can hold only two pending tasks. If four tasks are running and six more arrive before any worker finishes, how many can be queued?
📖 Explanation: All four workers are occupied, and the queue capacity is two. Therefore, only two of the six arriving tasks can enter the queue; the remaining four must follow the configured rejection or overflow policy.
Q27. A graph gives worker count and completed tasks per second: (1,20), (2,37), (3,49), (4,55), and (5,55). What trend is best supported?
📖 Explanation: Throughput rises from 20 to 55 tasks per second, then remains at 55 when the fifth worker is added. This suggests a bottleneck or saturation point where additional workers provide no measured gain.
Q28. A graph records worker count and average queue wait: (2,40 ms), (4,24 ms), (6,15 ms), (8,14 ms), and (10,14 ms). What conclusion follows?
📖 Explanation: Average queue wait falls from 40 to 14 milliseconds as the pool grows to eight workers, then remains unchanged. The measurements suggest additional workers beyond eight do not improve this workload's queue delay.
Q29. A pool is tuned for CPU-bound work on a four-core machine. The team increases workers from four to twenty, but throughput remains nearly unchanged while context switches rise. What is the best interpretation?
📖 Explanation: Four cores already provide four simultaneous ordinary CPU execution paths. Increasing runnable workers to twenty may add context switching and contention without adding hardware capacity, explaining why throughput remains nearly unchanged.
Q30. A team separates short queries from long conversions into two pools. Which result would most strongly support this change?
📖 Explanation: Separate pools can prevent long blocking conversions from occupying every worker needed by short queries. Improved query latency during bursts, while keeping memory and scheduling overhead acceptable, is evidence that workload isolation is useful.
Q31. A worker pool has three workers. Each worker runs a task that waits for another task queued in that same pool. The queue contains all three required follow-up tasks. What is the likely result?
📖 Explanation: All three workers are blocked waiting for follow-up tasks that remain queued. Since no worker is free to execute those tasks, the dependency cannot be satisfied and the pool can stop making progress.
Q32. A pool handles independent requests, but tasks have highly variable durations. Some workers become idle while another worker has a long backlog. Which mechanism can improve load distribution?
📖 Explanation: Work stealing lets an idle worker obtain available tasks from another worker's queue, improving load balance when task durations vary. Its benefit depends on queue design, dependencies, and the synchronization cost of stealing work.
Q33. A server receives 600 tasks per second, and each task occupies a worker for 0.01 seconds on average. Ignoring bursts and overhead, approximately how many workers are needed to match the average offered workload?
📖 Explanation: Average worker demand is arrival rate multiplied by average occupancy: worker-seconds per second. Six workers approximately match the average offered workload, but bursts and service-time variability may require headroom.