Chapter 9 The goroutine Scheduler
- 9.1 The Scheduling Problem and the GMP Model
- 9.2 Work-Stealing Scheduling
- 9.3 The MPG Model and Concurrent Scheduling Units
- 9.4 The Scheduling Loop
- 9.5 Thread Management
- 9.6 Signal Handling
- 9.7 Cooperation and Preemption
- 9.8 System Monitoring
- 9.9 The Network Poller
- 9.10 Timers
- 9.11 NUMA Awareness and the Future of the Scheduler
(Execution stack management originally belonged to this chapter; it has now been moved to Chapter 14 Execution Stack Management.)
In the author’s eyes, the Go scheduler is the most fascinating component in the entire runtime.
For Go itself, its design and implementation directly affect every other component of the Go runtime, and it is the part that deals directly with user-space code.
For Go users, the scheduler hides an extremely complex runtime machinery behind a single simple keyword, go.
To guarantee high performance, the scheduler must make effective use of the parallelism and locality of computation; to keep user space simple,
the scheduler must efficiently schedule the network poller and the garbage collector, which are invisible to user-space code; to guarantee the correctness of code
execution, it must also strictly implement the memory ordering of user-space code, and so on.
In short, the design of the scheduler directly determines the form that the Go runtime source code takes.