Look at this well known image taken from morsmachine.dk/go-scheduler
The gray lists are local runqueues of P. If this queue get empty they will be filled with go routines from the global runqueue.
The Question is, who fills the local runqueue of P?
Scheduler, without synchronisation or every P do it for himself (mutex)?
P.S. The article omits this information.
All of this is taken from golang.org/src/runtime/proc.go:
Function schedule
(the scheduler) calls findrunnable
which attempts to steal a G
from another P
. If that fails, it'll return a G
from the global run queue. That G
is then executed on the "current" M
.
In addition, schedule
checks the global run queue occasionally "for fairness":
// Check the global runnable queue once in a while to ensure fairness.
// Otherwise two goroutines can completely occupy the local runqueue
// by constantly respawning each other.
In all of that, only one lock is involved, which is lock(&sched.lock)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With