previous | start | next

Thread Context Switch

Switch function parameter: a pointer to a Thread Control Block

Calling thread saves the stack pointer (to its own stack) in its own Thread Control Block.

Calling thread loads the stack pointer register with the stack pointer value from the target Thread Control Block.

Calling thread executes ret, but this will return to the target thread's code since the stack pointer register points to the target thread instead of the original calling thread!



previous | start | next