Short answer: Round-robin scheduling runs the job at the head of a ready queue for a fixed quantum, then moves it to the tail if it is still ready. With n jobs continuously ready, a quantum q, and a context switch of length s, each job waits at most (n − 1)(q + s) between slices and receives a 1/n share of the processor, switches included. The policy prevents starvation. It does not minimize average turnaround, and it does not meet deadlines by itself.
What the problem actually asks
A first-come queue lets one long job hold the processor while short jobs wait. Round-robin slices the hold. The quantum is the longest a job may run before the scheduler looks at the queue again. A job that blocks for input leaves the queue early. A job that uses the whole quantum goes to the back, behind jobs that were already waiting.
The quantum is the entire policy decision. A very long quantum means each job runs to completion once it starts, which is first-come service in practice. A very short quantum spends the processor on context switches. The useful range sits where q is large next to s and small next to the interactive response the system wants.
What the algorithm guarantees
If n jobs stay ready, the wait between the start of two consecutive slices of the same job is at most (n − 1)(q + s). No ready job waits forever while the scheduler keeps running. Over a long interval the processor time, including switches, is split evenly among the jobs that were continuously ready. Extra memory is the queue. Preemption is required at quantum boundaries.
The even split is not an optimality claim about turnaround time. When every burst length is known in advance, shortest job first produces a smaller mean turnaround. Round-robin does not use burst lengths. It also does not use deadlines. A deadline test belongs to earliest-deadline-first or rate-monotonic analysis.
The working steps
- Keep ready jobs in a queue. Choose a quantum q.
- Dequeue the head and run it until it blocks, finishes, or has consumed q, whichever comes first.
- If it is still ready, enqueue it at the tail. If it blocked, put it on the structure that will wake it.
- A newly woken or newly arrived job joins the tail, unless a separate rule says otherwise.
- Charge the context switch s in any accounting that quotes a processor share. The share of the processor spent in switches is about s/(q + s) when every job uses a full quantum.
The wait bound assumes the scheduler actually preempts at q and that ready jobs are only those in this queue. Deadline feasibility is earliest deadline first or rate-monotonic scheduling. Mean-turnaround optimality with known bursts is shortest job first. Round-robin is the equal-slice queue.
Approaches that look simpler and fail
| Approach | Why it fails when the quantum grows to the longest job |
|---|---|
| Set q larger than every burst and still call the policy fair slicing | No job is preempted. The queue behaves as first-come, first-served. Fairness between a short job and a long job in front of it disappears. |
| Set q near the context-switch cost and quote a full 1/n of useful work | A large fraction of each cycle is the switch. The useful share is q/(q + s), split among the jobs. |
| Use the queue order as a deadline proof | The queue does not look at deadlines. A job can be sliced evenly and still finish late. |
| Leave a finished job in the queue | The remaining jobs keep paying a slice of processor time to a job that has no work. Completion has to unlink it. |
Deadlines on one processor are earliest deadline first. Fixed priorities by period are rate-monotonic scheduling. Round-robin is the quantum queue.
A working example
This Python fragment runs each ready job for a quantum of 2 and sends leftover work to the tail. Jobs of length 3 and 4 produce the slices A A B B A B.
from collections import deque
jobs = deque([("A", 3), ("B", 4)])
quantum = 2
slices = []
while jobs:
name, left = jobs.popleft()
run = min(quantum, left)
slices.extend([name] * run)
left -= run
if left:
jobs.append((name, left))
assert slices == ["A", "A", "B", "B", "A", "B", "B"]
print(*slices)
Where it is used
Linux SCHED_RR is round-robin among real-time tasks of equal priority: each task runs for a quantum, then joins the tail of its priority. Ordinary desktop scheduling is the fair scheduler, not this quantum. A quantum that is too long becomes first-come service.
When you can drop this algorithm
Drop round-robin when burst times are known and mean turnaround is the objective. Shortest job first uses those times. Keep the quantum when the requirement is that a ready job cannot be starved by one long neighbor.
Why this stays published
We publish this so a search for round-robin scheduling returns the quantum, the tail requeue, and the wait bound (n − 1)(q + s). Round-robin runs each ready job for a quantum and then sends it to the tail, so a job that stays ready waits at most (n − 1)(q + s) between slices.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
