📝 Why threads are used in operating system (33 MCQs)
Multiple Activities Within a Single Process
Threads are used to divide a process into independent execution paths that can perform different activities concurrently. Each thread maintains its own processor context and stack but shares the process address space and resources. This arrangement allows an application to handle user interaction, computation, file access, and communication without requiring a separate process for every activity.
Limitations of Single-Threaded Application Execution
A single-threaded application can become unresponsive when its only execution path blocks during network communication, disk access, or another lengthy operation. Creating separate processes for every task also introduces additional resource and communication overhead. Threads address these limitations by supporting concurrent activities within one process and allowing them to exchange data through shared memory.
Independent Execution Paths and Resource Sharing
An application creates threads through a threading library or operating system interface. Each thread receives its own stack, register state, and scheduling information. The scheduler allocates available CPU time to runnable threads, while all threads can access shared process memory, open files, and other permitted resources. Synchronisation controls access to shared data.
Keeping an Application Responsive During Network Access
Suppose a desktop application uses one thread for its interface and another for downloading a 20 MB file. When the download thread waits for network packets, the interface thread can continue processing mouse clicks and keyboard input. The application remains responsive because the waiting operation does not suspend every thread in the process.
Application Responsiveness and Efficient Resource Utilisation
Threads are valuable in interactive software, web servers, multimedia applications, and background processing systems. They support overlapping activities and reduce the need for independent process address spaces. However, shared resources require synchronisation, and excessive thread creation increases memory consumption and scheduling overhead. Blocking operations can also affect other threads when unsuitable synchronisation or process-level resources are used.
Misconceptions About the Purpose of Threading
'Threads are created only to increase processor speed' is incorrect because they also improve responsiveness and structure concurrent tasks. 'Every blocking operation blocks the entire process' is incorrect when other schedulable threads can continue. 'Threads provide automatic protection between tasks' is incorrect because threads normally share the same process address space.
Exam Focus: Reasons for Using Threads
Explain how threading improves responsiveness, resource sharing, and concurrency. Compare creating multiple processes with creating multiple threads in terms of memory and communication overhead. Given an application involving user interaction, computation, and I/O, identify suitable independent execution activities and explain the synchronisation needed when they access shared data.
Key Terms of Thread Utilisation
- Responsiveness - Ability to react promptly to input.
- Concurrency - Overlapping execution of activities.
- Blocking - Waiting for an event or resource.
- Shared resource - Resource accessible by multiple threads.
- Threading - Creating multiple execution paths.
- Synchronisation - Coordinating concurrent operations.
📝 All Why threads are used in operating system MCQs
Q1. A word processor must accept keystrokes, check spelling, and save changes in the background. Why is dividing these activities among threads useful?
📖 Explanation: Separate threads organize independent activities within one application. The interface can process input while spelling and saving work proceed, without requiring a separate process and address space for every activity.
Q2. A monitoring application receives sensor updates, refreshes a dashboard, and writes records to disk. What is the main reason to assign these activities to different threads?
📖 Explanation: Different activities often have different timing and waiting requirements. Separate threads let the scheduler run whichever execution path is ready, rather than forcing sensor handling, display updates, and disk writing into one sequential flow.
Q3. A single-threaded inventory program waits for a remote stock query before it can process another user action. Which redesign addresses the underlying limitation?
📖 Explanation: The single execution path cannot advance while its network operation is waiting. A separate worker thread can wait for the response while another ready thread handles user actions, improving overlap without requiring another process.
Q4. A mail client downloads a large attachment while the user continues composing a reply. Which arrangement most directly supports this behavior?
📖 Explanation: A download thread can wait for network data while the interface thread remains available to process typing and display updates. This arrangement separates independent work while keeping both activities within the same application process.
Q5. A developer claims that creating a worker thread gives it a private address space, so the worker cannot affect the main thread data. Which correction identifies the error?
📖 Explanation: The claim confuses threads with processes. Threads in one process normally share its address space, including global data and heap objects; this enables cooperation but also means that unsynchronized writes can affect other threads.
Q6. A desktop application performs a long report export after the user selects Export. Why can a separate worker thread improve the user experience?
📖 Explanation: Running the export in a worker leaves the interface execution path available for input, repainting, and status updates. The export may still consume CPU time, but it no longer has to occupy the only application thread.
Q7. A browser has one thread waiting for a network response and another thread ready to update the page controls. What normally allows the controls to remain usable?
📖 Explanation: A blocked thread cannot use the processor until its awaited event occurs. The scheduler can select another ready thread in the process, allowing controls to remain responsive while the network operation is pending.
Q8. A single-core application records this execution: worker runs from 0 to 2 ms, waits for disk I/O from 2 to 8 ms, and the interface thread runs from 2 to 5 ms. What does the trace demonstrate?
📖 Explanation: The worker is blocked from 2 to 8 ms, so the scheduler runs the ready interface thread during part of that interval. This is concurrency through interleaving, not simultaneous execution on one core.
Q9. A user-interface response-delay chart for a long background export contains these pairs: export duration in seconds and input delay in milliseconds: (1,8) ; (2,9) ; (3,8) ; (4,10) ; (5,9). Which conclusion is best supported?
📖 Explanation: Input delay stays between 8 and 10 milliseconds even as export duration rises from one to five seconds. The pattern is consistent with a responsive interface thread, but it does not prove execution on separate cores.
Q10. A student moves a long calculation to a worker thread but the interface still freezes whenever the worker updates a shared document. The student concludes that threads cannot improve responsiveness. What is the flaw in this reasoning?
📖 Explanation: The flawed conclusion ignores synchronization and shared-resource blocking. If the worker holds a lock needed by the interface, the interface may wait despite being a separate thread; thread separation alone does not guarantee responsiveness.
Q11. Which operating-system benefit is illustrated when an application continues accepting user input while a lengthy background operation is still running?
📖 Explanation: Responsiveness is the ability of an application to continue reacting to input while another part performs lengthy work or waits for an event. Separate threads can preserve this behavior when the interface remains runnable.
Q12. A web service handles independent client requests. Why might separate execution paths be preferable to processing every request in one strictly sequential flow?
📖 Explanation: With one sequential flow, a request waiting for network or storage can delay later requests. Multiple threads allow ready requests to progress while another waits, improving service responsiveness and the use of available processor time.
Q13. Which default property makes communication between threads of one process easier than communication between unrelated processes?
📖 Explanation: Threads belonging to one process normally share its address space, so they can communicate through common variables and objects. Separate processes generally need an explicitly arranged mechanism such as shared memory or message passing.
Q14. A database server uses several threads to process queries against one in-memory buffer pool. Which benefit of threads is most directly relevant?
📖 Explanation: Because query workers belong to the same process, they can access the common buffer pool directly. This avoids arranging a separate interprocess data-transfer mechanism, although concurrent updates to shared structures still require coordination.
Q15. A student argues that two processes and two threads communicate in exactly the same way because both can exchange data. Which statement corrects this comparison?
📖 Explanation: The error is treating the communication setup as identical. Threads in one process can access shared memory directly, while separate processes normally need mechanisms such as configured shared memory, pipes, or message passing.
Q16. A photo application has one thread decode image tiles and another prepare them for display. Why is a shared in-memory tile queue useful?
📖 Explanation: A shared queue lets the decoder place tile references in process memory and the display thread retrieve them directly. This simplifies communication, but queue operations still need coordination to prevent conflicting concurrent updates.
Q17. A document editor uses a worker to autosave while the interface displays the same document. Which combination best explains why threads are suitable for this design?
📖 Explanation: Threads support both goals: the worker and interface can access the same document data, and separate execution paths can progress independently. Synchronization or a consistent snapshot is still needed while edits and saving overlap.
Q18. Why is creating a thread within an existing process generally more economical than creating another process for a related task?
📖 Explanation: A new thread reuses the process address space and many existing resources. It still needs its own execution context and stack, but it usually requires less setup and memory than creating a separate process.
Q19. A system measures task-start overhead as 4 ms for a new process and 1 ms for a new thread. If 12 tasks are started sequentially, how much setup time is saved by using threads under these measurements?
📖 Explanation: Process setup takes ms, while thread setup takes ms. The saved time is ms; these figures describe the stated measurements, not a universal ratio.
Q20. A student says switching between two threads in the same process requires no processor-state saving because both use one address space. Which part of the explanation is incorrect?
📖 Explanation: The flawed step is assuming a shared address space eliminates context management. The operating system must still preserve and restore registers, the program counter, and stack state, even when no process address-space change is needed.
Q21. A program already has one process loaded. It creates a worker thread to perform a related calculation. Which operation can usually be avoided compared with launching a separate process?
📖 Explanation: The worker reuses the existing process address space, so a separate set of process memory mappings does not need to be established. The thread still requires its own stack, registers, program counter, and scheduling information.
Q22. Why should thread creation be described as lower-overhead rather than cost-free?
📖 Explanation: Thread creation avoids much of the setup required for a separate process, but it still allocates a stack and records execution and scheduling state. Creating excessive threads can therefore consume memory and management time.
Q23. A scientific program launches 500 threads, but each performs only a tiny amount of work. Which observation best explains why this can reduce rather than improve efficiency?
📖 Explanation: Threads are cheaper than processes, not free. When each task performs very little work, creation, scheduling, and context-switching costs can outweigh computation, so a smaller number of threads handling larger work units may be more efficient.
Q24. Which statement describes concurrency as a reason for using threads on a single-core processor?
📖 Explanation: On a single core, only one thread executes instructions at an instant, but the scheduler can interleave their execution. This lets multiple activities make progress during overlapping time intervals, even without hardware parallelism.
Q25. An I/O-bound server reports completed requests as the number of worker threads changes: (1,10) ; (2,18) ; (3,24) ; (4,27) ; (5,27), where each pair is (workers, requests per second). What trend is shown?
📖 Explanation: Throughput rises from 10 to 27 requests per second as workers increase from one to four, then remains at 27 with five. Overlapping I/O waits initially helps, but another worker adds no measured throughput.
Q26. A single-core file service has one thread waiting for disk data while another thread processes an already available block. Which reason for using threads does this illustrate most directly?
📖 Explanation: The disk-waiting thread cannot use the processor, so the ready processing thread can perform useful work. This overlap improves utilization through concurrency, although the single core still executes only one thread at a time.
Q27. A media application reads chunks from storage and processes previously read chunks. Why can separate threads improve the flow of this work?
📖 Explanation: The reader and processing thread can progress independently. When storage access blocks the reader, the other thread can process data already available, reducing idle time and avoiding a strictly sequential read-then-process workflow.
Q28. A workstation has eight CPU cores but runs a CPU-bound application containing only one execution thread. Which statement best describes the application's ability to use those cores for its own work?
📖 Explanation: A single execution thread can run on only one core at a time. Additional threads provide independent execution paths that the scheduler may place on different cores, subject to dependencies, available work, and system scheduling.
Q29. A parallel service records throughput as core count and completed jobs per second: (1,100) ; (2,185) ; (3,255) ; (4,310) ; (5,330). Which conclusion best fits the measurements?
📖 Explanation: Throughput increases from 100 to 330 jobs per second, but successive gains shrink from 85 to 20. The data show improved scalability with diminishing returns rather than a constant or perfectly linear increase.
Q30. A student states that using several threads on a single-core computer makes their instructions run in parallel. Which correction is accurate?
📖 Explanation: The student's error is confusing concurrency with parallelism. A single core switches among runnable threads, allowing overlapping progress over time, but simultaneous instruction execution requires multiple execution cores or processors.
Q31. Two worker threads update different records in a shared in-memory table while running on separate cores. Which statement best captures both the opportunity and the concern?
📖 Explanation: Threads can execute on separate cores while accessing one process address space. If their operations overlap on shared data, synchronization may be needed to prevent inconsistent updates; sharing memory does not itself prevent parallel execution.
Q32. A service has nine independent CPU-bound jobs, each requiring 2 ms of CPU time. With four available cores, assume ideal balancing and no overhead. What is the minimum completion time when the jobs are assigned to threads?
📖 Explanation: Four cores can process four jobs in each 2 ms wave. Nine jobs require three waves, so the ideal completion time is ms, compared with 18 ms if one core handles all jobs sequentially.
Q33. A document-processing service needs strong fault isolation because a failure in one task must not corrupt or terminate the others. Why might separate processes be preferable to threads in this case?
📖 Explanation: Threads are efficient when activities need shared memory, but that sharing weakens isolation. Separate processes provide distinct address spaces, reducing the chance that one task directly corrupts another task memory or execution environment.