Scheduler¶
Category: Scheduling · Status: stub
One line: The part of an operating system or runtime that decides which ready thread or task runs next, on which core, and for how long.
Also called: thread scheduler, process scheduler.
How it connects¶
flowchart LR
n_context_switch["Context switch"]
n_scheduler["Scheduler"]
n_scheduling_policy["Scheduling policy"]
n_scheduler -->|uses| n_context_switch
n_scheduler -->|uses| n_scheduling_policy
classDef center stroke-width:3px
class n_scheduler center
classDef outside stroke-dasharray: 4 3
class n_context_switch,n_scheduling_policy outside
- Is built on: Context switch, Scheduling policy
- See also: Context switch, Green threads and M:N scheduling, Thread
In each language¶
| Rust | Threads are scheduled by the OS; async tasks by the chosen runtime, such as Tokio's ↗ |
| Go | The runtime schedules goroutines onto threads, running Go code on at most GOMAXPROCS ↗ CPUs at once |
| Java | Platform threads by the OS; virtual threads ↗ by a scheduler in the JDK, using as many platform threads as there are processors by default |
| C# | TaskScheduler ↗ decides where tasks run |
| Kotlin | A CoroutineDispatcher ↗, such as Dispatchers.Default or Dispatchers.IO, runs coroutines on its pool of threads |
| Erlang and Elixir | Scheduler threads ↗ (+S), by default one per logical processor |
| Haskell | setNumCapabilities ↗ sets how many Haskell threads can run truly simultaneously |
| The operating system | sched(7) ↗: Linux's policies SCHED_OTHER, SCHED_FIFO, SCHED_RR and SCHED_DEADLINE |
Where to read more¶
- In the books: Concurrency in C# Cookbook, Stephen Cleary — ch. 13, 'Scheduling'
- In the books: Combine: Asynchronous Programming with Swift, Shai Mishali, Florent Pillet, Marin Todorov, Scott Gardner — ch. 17, 'Schedulers'
- In the books: Programming with POSIX Threads, David R. Butenhof — ch. 5, 'Advanced Threaded Programming' → 'Realtime scheduling'
- In the books: Pro TBB, Michael Voss, Rafael Asenjo, James Reinders — ch. 11, 'Controlling the Number of Threads Used for Execution' → 'A Brief Recap of the TBB Scheduler Architecture'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 6, 'Concurrent Programming with Reactive Extensions' → 'Rx schedulers'
- In the books: Parallel and Concurrent Programming in Haskell, Simon Marlow — ch. 4, 'Dataflow Parallelism: The Par Monad' → 'Using Different Schedulers'
- Reference: Wikipedia: Scheduling (computing) ↗