Context Switch
PronunciationKON-tekst SWICH
Definition
A context switch is when the CPU stops running one process or thread and starts another. The operating system saves the first one's state and loads the second's, which takes a little time.
Where you hear it
In OS courses, performance profiling (high context-switch counts) and discussions on threads versus async.
Examples
Thousands of threads cause heavy context switching.
Each task gets a short time slice before being switched out.
Too many threads on four cores caused frequent context switches and slow responses.
Common mistake
Creating far more threads than cores. The CPU then spends more time switching than working.
Don't confuse with
A function call, which just jumps within the same thread and costs almost nothing.
Say it at work
- In a meeting or chat
The context-switch rate is very high.
- In an email or ticket
Use a pool sized to the number of cores.
Keep exploring
More in Programming Fundamentals