Skip to content

Commit 1868b82

Browse files
committed
Simplify looping in case of spurious wakeups
1 parent dd7ad95 commit 1868b82

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,10 @@ internal class CoroutineScheduler(
709709
return
710710
}
711711
assert { localQueue.size == 0 }
712-
while (inStack()) {
712+
workerCtl.value = PARKED // Update value once
713+
while (inStack()) { // Prevent spurious wakeups
713714
if (isTerminated || state == WorkerState.TERMINATED) break
714715
tryReleaseCpu(WorkerState.PARKING)
715-
workerCtl.value = PARKED
716-
if (!inStack()) return
717716
interrupted() // Cleanup interruptions
718717
park()
719718
}

0 commit comments

Comments
 (0)