Preemptive scheduling¶
Category: Scheduling · Status: stub
One line: The scheduler may stop a running thread at any moment, usually on a timer interrupt, and run another — no thread can hog the CPU, and any step can be interrupted.
Also called: preemption, preemptive multitasking.
How it connects¶
flowchart LR
n_cooperative_scheduling["Cooperative scheduling"]
n_earliest_deadline_first["Earliest deadline first"]
n_preemptive_scheduling["Preemptive scheduling"]
n_rate_monotonic_scheduling["Rate-monotonic scheduling"]
n_scheduling_policy["Scheduling policy"]
n_cooperative_scheduling ---|vs| n_preemptive_scheduling
n_earliest_deadline_first -->|is a| n_preemptive_scheduling
n_preemptive_scheduling -->|is a| n_scheduling_policy
n_rate_monotonic_scheduling -->|is a| n_preemptive_scheduling
classDef center stroke-width:3px
class n_preemptive_scheduling center
classDef outside stroke-dasharray: 4 3
class n_cooperative_scheduling,n_earliest_deadline_first,n_rate_monotonic_scheduling,n_scheduling_policy outside
- Is a kind of: Scheduling policy
- Kinds: Earliest deadline first, Rate-monotonic scheduling
- Often confused with: Cooperative scheduling
- See also: Context switch, Goroutine, Interleaving, Multitasking
In each language¶
| Go | Goroutines have been asynchronously preemptible since Go 1.14 ↗; before that, a loop without function calls could hold up the scheduler |
| Python | Threads get timeslices set by the switch interval ↗, and the operating system picks which runs next: the interpreter has no scheduler of its own |
| JavaScript | Never: a function runs to completion ↗ before other code on the same thread runs |
| Haskell | GHC preempts a thread ↗ only when it allocates memory, so a tight loop that never allocates can lock out other threads |
| The operating system | sched(7) ↗: a higher-priority thread preempts a lower one; SCHED_RR also takes turns by time slice |
Where to read more¶
- In the books: Pro TBB, Michael Voss, Rafael Asenjo, James Reinders — ch. 14, 'Using Task Priorities' → 'Support for Non-Preemptive Priorities in the TBB Task Class'
- Reference: Wikipedia: Preemption (computing) ↗