A context switch occurs when a computer’s CPU switches from one process or thread to a different process or thread.
Context switching allows for one CPU to handle numerous processes or threads without the need for additional processors.
Any operating system that allows for multitasking relies heavily on the use of context switching to allow different processes to run at the same time.
Typically, there are three situations that a context switch is necessary, as shown below.
§ When the CPU needs to switch processes in and out of memory, so that more than one process can be running.
Kernel/ User Switch:
§ When switching between user mode to kernel mode, it may be used.
§ When the CPU is interrupted to return data from a disk read.