Description
openedon Nov 9, 2023
Julia does need the ability to pin a task to a thread (in our current terminology: make it sticky). This currently happens implicitly for tasks created with Base.@async
to support its semantics. To support those semantics, the parent task must also be made sticky. More precisely, if a newly created task S
is sticky (which they are when created with Task()
or @task
), then whichever task calls schedule(S)
will also be made sticky. A task that calls the AsyncCondition(callback)
constructor (which spawns an @async
task) will become sticky, as will a task that calls Timer(callback)
.
This sort of stickiness-infection ignores threadpool boundaries -- a task created on the default threadpool can end up being stuck to an interactive thread.
We can fix some of these (as we have previously), but we cannot fix them all, due to @async
semantics.
Furthermore, such stickiness-infected tasks are never unstuck. There is this PR which attempts to unstick such tasks, but adds too much overhead.
We should introduce an explicit task pin/unpin interface (see #52108) and deprecate Base.@async
so that all this implicit stickiness and associated cruft can be removed from the runtime.