Compare common CPU scheduling algorithms.
CPU scheduling decides which runnable thread runs next. Common policies:
- First Come First Served: simple and non-preemptive, but suffers the convoy effect when a long job blocks short ones.
- Shortest Job First: optimal average waiting time if burst lengths are known, but starvation is possible and bursts are usually guessed.
- Round Robin: each thread gets a time quantum; good response time, and the quantum trades context-switch overhead against interactivity.
- Priority: the highest priority runs; ageing prevents starvation.
- Multilevel feedback queue: multiple queues with different quanta, promoting interactive jobs and demoting CPU-bound ones.
RR with q=4: A(10) B(3) -> A4 B3 A4 A2
Real schedulers such as Linux's CFS approximate fair sharing by tracking virtual runtime rather than fixed priorities, and modern kernels also care about cache locality and NUMA. The right choice depends on whether the goal is throughput, latency or fairness.