Work stealing is a scheduling technique that keeps processors busy by moving goroutines between local run queues. When one queue becomes empty, its kernel-level thread takes work from another queue instead of remaining idle. section 2.3.2 section 2.6
Go’s runtime uses work stealing in two closely related situations:
- A goroutine makes a blocking call, such as waiting for I/O. The runtime moves its queue to a new or reused kernel-level thread so other goroutines can continue. section 2.3.2
- A local run queue becomes empty while another queue still contains goroutines. The idle thread steals work from the busy queue, improving processor utilization. section 2.3.2
- The technique supports parallel execution because Go places goroutines across multiple kernel-level threads, which can run on multiple processors. section 2.6
A blocked worker and a replacement
Imagine two kernel-level threads executing goroutines from separate local run queues. If a goroutine on thread B waits for I/O, the runtime creates or reuses thread C and moves work so the remaining goroutines keep running. Thread C can then steal tasks from the affected queue rather than waiting for the I/O operation to finish. section 2.3.2
Figure 2.10 (a) Kernel-level threads A and B are executing goroutines from their respective LRQs; (b) a goroutine is waiting on I/O blocking thread B, resulting in the creation or reuse of a new thread C, stealing work from the previous thread.
Shows local run queues before and after I/O blocks a thread, including the creation or reuse of a thread that steals work. section 2.3.2




