Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Base.@async #52109

Open
kpamnany opened this issue Nov 9, 2023 · 4 comments
Open

Deprecate Base.@async #52109

kpamnany opened this issue Nov 9, 2023 · 4 comments
Labels
deprecation This change introduces or involves a deprecation julep Julia Enhancement Proposal multithreading Base.Threads and related functionality

Comments

@kpamnany
Copy link
Contributor

kpamnany commented 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.

@kpamnany
Copy link
Contributor Author

kpamnany commented Nov 9, 2023

We cannot actually remove Base.@async until Julia 2.0 of course, as it would be a breaking change. But deprecating it with a suggestion to:

  • use pin/unpin if you want to stay on the same thread to call into a library, and
  • use @spawn and a lock or channel to interact with another task if you want Base.@async semantics,

Should be possible.

@NHDaly NHDaly added multithreading Base.Threads and related functionality deprecation This change introduces or involves a deprecation julep Julia Enhancement Proposal labels Nov 27, 2023
@jam-khan
Copy link
Contributor

Hi, I would like to work on this issue. I am a beginner to open-source. If I could get some resources, or similar PR that deprecates something, that would be great! Thanks a lot!

@nsajko
Copy link
Contributor

nsajko commented Jul 26, 2024

Deemphasizing @async in the docs seems like it should come before trying to deprecate it, xref #50356.

@IanButterworth
Copy link
Member

IanButterworth commented Jul 26, 2024

Renaming (deprecating) the Threads module to Tasks, which has been discussed, would help generalize the meaning via the form Tasks.@spawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation julep Julia Enhancement Proposal multithreading Base.Threads and related functionality
Projects
None yet
Development

No branches or pull requests

5 participants