diff --git a/src/runtime/scheduler_cores.go b/src/runtime/scheduler_cores.go index cfec67500d..931d7e12ff 100644 --- a/src/runtime/scheduler_cores.go +++ b/src/runtime/scheduler_cores.go @@ -195,18 +195,6 @@ func run() { func scheduler(_ bool) { for mainExited.Load() == 0 { - // Check for ready-to-run tasks. - if runnable := runqueue.Pop(); runnable != nil { - // Resume it now. - setCurrentTask(runnable) - runnable.RunState = task.RunStateRunning - schedulerLock.Unlock() // unlock before resuming, Pause() will lock again - runnable.Resume() - setCurrentTask(nil) - - continue - } - var now timeUnit if sleepQueue != nil || timerQueue != nil { now = ticks() @@ -253,6 +241,18 @@ func scheduler(_ bool) { } } + // Check for ready-to-run tasks. + if runnable := runqueue.Pop(); runnable != nil { + // Resume it now. + setCurrentTask(runnable) + runnable.RunState = task.RunStateRunning + schedulerLock.Unlock() // unlock before resuming, Pause() will lock again + runnable.Resume() + setCurrentTask(nil) + + continue + } + // At this point, there are no runnable tasks anymore. // If another core is using the clock, let it handle the sleep queue. if hasSleepingCore() {