A context switch occurs when a CPU core switches from executing code on one thread, to executing code on a different thread, or going to idle. When the OS switches the thread that is running on a CPU, it must save and restore state, both for the thread that is being switched out, and for the thread that is being switched in. This state, or ...