Context switching is a term used to describe the method used by a kernel to switch between different processes. A context switch can occur at any stage the kernel is called, system calls, during an interrupt or exception. Context switches can occur between instructions(not program statements by assembler). Context switches are transparent to threads and processes except for elasped time. It is the kernels responsibility to save the current context and return it.
Thread/Process Switch Edit
Push a trap frame onto the processes/threads stack. It usually contains user-level stack pointer and program counter as well as virtual address space.
Pushes a C activation stack which contains
Push the kernel state onto the stack. This saves all the registers that the calling convention expects to be saved.
A new process/thread is selected and the infromation is pulled off the prospective stack in the opposite order. The context switch is then complete.