A global queue is a scheduler queue shared among all Ps for goroutines that are runnable but cannot execute immediately. It complements one local queue per P. section 8.2.1
When selecting runnable goroutines, the scheduler:
- Checks the global queue every sixty-first execution. section 8.2.1
- Checks the current P’s local queue when no global-queue goroutine is selected. section 8.2.1
- Can steal goroutines from other Ps when both queues are empty, allowing an idle processor to find work. section 8.2.1
runtime.schedule() {
// Only 1/61 of the time, check the global runnable queue for a G.
// If not found, check the local queue.
// If not found,
// Try to steal from other Ps.
// If not, check the global runnable queue.
// If not found, poll network.
}
Use the scheduling pseudocode to trace global-queue checks, local-queue checks, work stealing, and network polling. section 8.2.1
