Context Switches: Voluntary and Involuntary
On a uniprocessor, the set of possible execution schedules depends on when context switches can occur.
- Voluntary: one thread explicitly yields the CPU to another.
E.g., a Nachos thread can suspend itself with Thread::Yield.
It may also block to wait for some event with Thread::Sleep.
- Involuntary: the system scheduler suspends an active thread, and switches control to a different thread.
Thread scheduler tries to share CPU fairly by timeslicing.
Suspend/resume at periodic intervals (e.g., nachos -rs)
Involuntary context switches can happen “any time”.