-
A scheduler is a program that decides which process should be executed next
-
The Golang Scheduler is used to schedule go routines to the kernel-space threads
-
Scheduler is responsible for adding and removing go routines from a run queue
-
The priority of the run queue is FIFO
Pre-emption
-
Pre-emption is the ability of a scheduler to pre-empt (stop) a goroutine running for more than 10ms and execute another goroutine
-
Pre-empted goroutines are added to the global run queue (also a FIFO queue)
-
When a kernel thread is blocked by a system call, the goroutines will go to another thread
Mutex
- A mutex is a lock that is used to synchronise access to a shared resource
- The run queue acts as a shared resource
- A mutex ensures that only one kernel thread can access the run queue at a time
- If a thread’s run queue is full, then the goroutine will be added to the global run queue
Work Stealing
- Work stealing is a technique that is used to balance the load between the processor’s kernel threads
- If a processor is idle, it will steal work from another processor or the global run queue, or the network poller