We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 15407e3 commit 0e1e607Copy full SHA for 0e1e607
core/kotlinx-coroutines-core/src/scheduling/CoroutineScheduler.kt
@@ -460,10 +460,11 @@ internal class CoroutineScheduler(
460
// Double check for overprovision
461
if (cpuWorkers >= corePoolSize) return 0
462
if (created >= maxPoolSize || cpuPermits.availablePermits() == 0) return 0
463
- // start & register new worker
464
- val newIndex = incrementCreatedWorkers()
+ // start & register new worker, commit index only after successful creation
+ val newIndex = createdWorkers + 1
465
require(newIndex > 0 && workers[newIndex] == null)
466
val worker = Worker(newIndex).apply { start() }
467
+ require(newIndex == incrementCreatedWorkers())
468
workers[newIndex] = worker
469
return cpuWorkers + 1
470
}
0 commit comments