julia
223fade5 - Fix `threads` test hangs when there are fewer cores than threads (#63833)

Commit
33 days ago
Fix `threads` test hangs when there are fewer cores than threads (#63833) * partr: Yield the OS thread while polling a task pinned to another thread A non-sticky task that parks in its own `wait()` stays bound to its thread until that thread switches away from it. Other threads still see it in the multiqueue, but `multiq_deletemin` cannot take it, so they keep polling it in `task_get_next`. When there are fewer cores than threads, this spinning starves the one thread that can run the task (and thread 1's event loop, which delays `Timer`s). On a single core with 4 threads, 5000 `Event` handoffs between two threads took 85 s. The polling threads cannot simply go to sleep: the owner may switch to a different task and only release the parked one afterwards, without waking anyone, so a sleeping pool could leave a runnable task stranded. Keep polling, but yield the OS thread (`sched_yield`, `SwitchToThread` on Windows) after each miss, so the owner can run. The handoffs above now take under 0.1 s, with no change on 2 or 4 cores. * test: Yield the OS thread in `threads_exec.jl` busy-wait loops The Peterson lock in `test_fence` and the CAS loop in `test_atomic_cas!` spin without ever giving up the OS thread. Since #63610 the `threads` test no longer runs alone on node 1, and when the process gets fewer cores than it has threads, the spinning thread can keep the thread it waits for from running for a very long time, until the watchdog kills the test. Call `Libc.systemsleep(0)` every 1000 spins. CI failures: https://buildkite.com/julialang/julia-ci/builds/876, https://buildkite.com/julialang/julia-ci/builds/906, https://buildkite.com/julialang/julia-ci/builds/908, https://buildkite.com/julialang/julia-ci/builds/892, https://buildkite.com/julialang/julia-ci/builds/910
Author
Loading