Abstract
- The ability to instruct the CPU to switch the task it is working on, so that each task can take turns to run - this is what powers Multi-tasking
- Context switching relies on the Process Control Block (PCB) to store the task state, so when we resume the task, we don’t have to start from scratch; we can continue the task as if it never stopped
Switching Speed | Memory Overhead | Isolation | |
---|---|---|---|
Process Context Switch | Slow | High | ✅ |
Thread Context Switch | Fast | Low | ❌ |
Process Context Switch
An expensive operation
- We not only need to save & load Register, we also need to use an entirely different Process Control Block (PCB) which may require us to switch out Memory Page which is an expensive operation
Thread Context Switch
Low overhead
The Address Space and per-process items are remain unchanged when threads are switched within the same Process (进程). This avoids switching out the Memory Page which is an expensive operation.