Learning path

Full curriculum

Full curriculum

Unit content

Scheduling and context switching

Several runnable computations can share processors because the operating system repeatedly chooses which execution context runs next.

Runnable and waiting

A process that is ready to execute is runnable. One waiting for input, a timer or another event can be blocked instead of occupying the CPU.

The kernel's scheduler chooses among runnable work according to a scheduling policy.

Execution context

To stop execution and later resume it, the system preserves the machine state that determines where computation continues. This includes values such as the program counter, stack pointer and general-purpose registers.

Context switching

A context switch replaces one active execution context with another:

A running
  ↓ save A
scheduler
  ↓ restore B
B running

The switch performs no application work and can also disturb caches or address-translation state, so it has overhead.

Multiplexing a processor

On one core, runnable work can be concurrent by taking turns. On several cores, several execution contexts can run simultaneously while the scheduler still decides how work is distributed.

A process initially provides one such execution context. Later, threads will allow several independently schedulable contexts to exist inside one process.