所有这些都来自golang.org/src/runtime/proc.go:函数schedule(调度程序)调用findrunnable试图G从另一个P. 如果失败,它将G从全局运行队列中返回 a 。这G是然后在“当前”执行M。此外,schedule偶尔检查全局运行队列“为了公平”:// 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.在所有这些中,只涉及一个锁,即lock(&sched.lock).