A context switch saves the state of the running process or thread (registers, program counter, stack pointer) in its PCB and loads the saved state of another, so the CPU can multitask.
Costs: the saving and loading work itself, scheduler overhead, and indirect costs such as cache and TLB invalidation (especially when switching between processes with different address spaces), which make the next instructions slower.
Thread switches inside the same process are cheaper because the address space stays the same. Reduce context switching by limiting runnable threads and system call churn.
Loading…