julia
0d4d6d92 - Scheduler: Use a "scheduler" task for thread sleep (#57544)

Commit
267 days ago
Scheduler: Use a "scheduler" task for thread sleep (#57544) A Julia thread runs Julia's scheduler in the context of the switching task. If no task is found to switch to, the thread will sleep while holding onto the (possibly completed) task, preventing the task from being garbage collected. This recent [Discourse post](https://discourse.julialang.org/t/weird-behaviour-of-gc-with-multithreaded-array-access/125433) illustrates precisely this problem. A solution to this would be for an idle Julia thread to switch to a "scheduler" task, thereby freeing the old task. This PR uses `OncePerThread` to create a "scheduler" task (that does nothing but run `wait()` in a loop) and switches to that task when the thread finds itself idle. Other approaches considered and discarded in favor of this one: https://github.com/JuliaLang/julia/pull/57465 and https://github.com/JuliaLang/julia/pull/57543.
Author
Parents
Loading