Thread Switch
Switching between threads is much faster than switching between processes (which we call Process Switching). But why?
Both thread switching and process switching need to save the current context onto the control stack.
The fundamental reason is because threads of a given process exist within the same user address space. Look at the mechanism for Process Switch, and realize that there is no change in memory space so much faster.
-
Though context still need to be saved Memory Context: The most significant factor making process switches slower is the need to change the memory context. Processes have their own separate memory spaces, and switching between processes involves:
-
Loading the page table: When switching processes, the operating system needs to load the page table of the new process into the memory management unit (MMU). This controls the virtual to physical memory mappings, which is not necessary when switching threads within the same process as they share the same memory space.