- 2074 Bhadra · 2+2 marks
Process vs thread; context switching
Short answer
In process switching, the entire address space must be changed, flushing caches. Threads within the same process share address space and resources; switching among them only saves program counter and registers, avoiding memory-map switches and TLB flushes, greatly reducing overhead.
Difference between process and thread. Explain how thread based execution minimizes context switching problem of process based execution.
Process vs thread
| Basis | Process | Thread |
|---|---|---|
| Meaning | Program in execution with its own resources | Unit of execution inside a process |
| Address space | Private | Shared with other threads of the process |
| Creation and switch time | High | Low |
| Communication | IPC mechanisms (pipes, messages) | Shared memory, directly |
| Protection | Protected from other processes | None among threads of the same process |
| Control block | Own PCB with memory maps, files | Small thread control block (PC, registers, stack) |
How threads minimise context-switch cost
In process-based execution, a context switch must save the registers and PCB of the old process, switch the address space (memory maps, page tables) and usually flush the TLB and cache of the old process. This is heavy overhead and no useful work is done meanwhile.
In thread-based execution, the concurrent activities are threads of one process. When the CPU switches between threads of the same process:
- only the program counter, registers and stack pointer must be saved and restored (a small thread control block);
- the address space, open files and other resources are shared and unchanged, so no memory-map switch and no TLB/cache flush is needed;
- with user-level threads the switch is done by a library procedure in user space without even trapping to the kernel.
Therefore thread switching is much faster and the system spends more time on useful work. Moreover, threads share data directly, so the number of expensive IPC-induced process switches is reduced (for example, a web server uses one thread per request instead of one process per request).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Process vs thread; multithreading advantages · Operating System, chapter 2
- What is process; process vs thread · Operating System, chapter 2
- Process vs thread; user and kernel threads · Operating System, chapter 2
- Context switching, 5-state model, MLFQ · Operating System, chapter 2
- Critical section problem; why execute quickly · Operating System, chapter 3
- Preemptive vs non-preemptive; process states · Operating System, chapter 2
- Context switching; distributed vs network OS · Distributed System, chapter 3
- Process vs thread and task states · Embedded System, chapter 6
- Context switching in RTOS · Embedded System, chapter 6 · asked 3×
- Process versus thread differences · Embedded System, chapter 6 · asked 4×