[Previous] [Contents] [Next]

Context Switching

Context switching is integral to threading and a difficult concept for some, so let me give a brief overview here in the "Threading Basics" section.

The processor uses a hardware timer to determine when a timeslice has ended for a given thread. When the hardware timer signals the interrupt, the processor saves all registers for the current thread onto the stack. Then the processor moves those same registers from the stack into a data structure called a CONTEXT structure. When the processor wants to switch back to a previously executing thread, it reverses this procedure and restores the registers from the CONTEXT structure associated with the thread. This entire procedure is called context switching.

[Previous] [Contents] [Next]