What Does a Context Switch Actually Switch?
“Switch to another task” sounds light, as if the CPU simply moves from one piece of code to another.
The real operation is more concrete. While the CPU is running an execution flow, registers contain intermediate state, the stack contains the call chain, the program counter points to the next instruction, and the scheduler knows whether the flow is running, ready, or blocked. To run another thread or task, the system must save the current state and restore another one.
Read More