Context switching saves one thread’s execution state and loads another thread’s state so a CPU can alternate between sequences of work. The operating system also removes blocked threads from CPU scheduling until file, network, or inter-thread waiting completes. section 1.1
Context switching has practical costs and purposes:
- The CPU timer can trigger a switch between threads, creating the appearance of simultaneous execution on one CPU. section 1.1 section 1.6
- Each switch adds overhead because the processor must preserve the current thread’s status and restore another’s. section 1.1 section 1.6
- Blocking operations release the CPU rather than wasting time scheduling a thread that cannot proceed. section 1.1
- Asynchronous programming avoids waiting on the thread during external operations, resuming processing after completion notification. section 1.6
The pizzeria analogy
A cook alternates between pizzas when timers beep, putting one aside and restoring another task. The repeated storing and picking up mirrors context switching, while waiting for an oven resembles a blocked thread. section 1.1
Figure 1.2 Single-threaded versus multithread with multiple requests
Compare single-threaded and multithreaded request flows to see why switching supports multiple outstanding requests. section 1.1








