---
title: "Process vs thread; context switching"
subject: "Operating System"
chapter: 2
key: "semester_6/operating_system:thread-context-switching"
source: https://www.bctengineer.com/q/semester_6/operating_system/thread-context-switching
site: BCT Engineering
---

# Process vs thread; context switching

Operating System · Chapter 2: Process Management

- Asked in: 2074 Bhadra, 2+2 marks
- Video: [Context Switching Explained | Process vs Thread Switching | Operating Systems | L-12](https://www.youtube.com/watch?v=W1p0LvhX36w) — Concept Core
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/thread-context-switching
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-2

## Question

Difference between process and thread. Explain how thread based execution minimizes context switching problem of process based execution.

## 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.

## Answer

#### 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).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why is a process context switch heavy?
   A. Only the program counter is saved
   B. It saves the PCB and registers, switches the address space and usually flushes the TLB and cache
   C. It needs no memory operations
   D. It is done only in user space
   Answer: B. Switching address space and flushing TLB/cache adds large overhead during which no useful work is done. (Key point: Process switch cost)

2. What must be saved and restored when switching between threads of the same process?
   A. Page tables and open files
   B. Program counter, registers and stack pointer
   C. The whole address space
   D. The TLB contents
   Answer: B. Address space and resources are shared and unchanged, so only PC, registers and stack pointer are switched. (Key point: Thread switch saves)

3. How does the web-server example show threads reducing switching?
   A. One process per request is used
   B. One thread per request is used, sharing data directly without IPC-induced process switches
   C. Requests are queued on disk
   D. Each request gets its own address space
   Answer: B. Threads share data directly, reducing the number of expensive IPC-induced process switches. (Key point: Reducing IPC switches)

## Related in Operating System

- [Process vs thread; multithreading advantages](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aprocess-thread-multithreading) — Operating System, chapter 2
- [What is process; process vs thread](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aprocess-vs-thread-define) — Operating System, chapter 2
- [Process vs thread; user and kernel threads](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aprocess-vs-thread-user-kernel-threads) — Operating System, chapter 2
- [Context switching, 5-state model, MLFQ](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acontext-switch-5state-mlfq) — Operating System, chapter 2
- [Critical section problem; why execute quickly](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acritical-section-thread-quick) — Operating System, chapter 3
- [Preemptive vs non-preemptive; process states](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apreemptive-nonpreemptive-process-states) — Operating System, chapter 2

## Related in other subjects

- [Context switching; distributed vs network OS](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Acontext-switch-dos) — Distributed System, chapter 3
- [Process vs thread and task states](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aprocess-thread-and-task-states) — Embedded System, chapter 6
- [Context switching in RTOS](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acontext-switching) — Embedded System, chapter 6, asked 3×
- [Process versus thread differences](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aprocess-vs-thread) — Embedded System, chapter 6, asked 4×
