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

Synchronous nature of join might result in suboptimal use of compute resources #1077

Open
zopsicle opened this issue Jul 12, 2023 · 1 comment

Comments

@zopsicle
Copy link

zopsicle commented Jul 12, 2023

The documentation for join reads:

…; if however closure B has been stolen, then it will look for other work while waiting for the thief to fully execute closure B.

Even if closure B completes before the “other work” completes, the code following the call to join cannot run immediately after closure A and closure B complete, even if there is a free thread on the thread pool. It must wait for the “other work” to complete, which might take a long time compared to closures A and B, with no way to prefer certain tasks to be considered “other work” candidates (AFAIK).

This is only really an issue because join must return on the calling thread, by its synchronous nature. Having an async version of join (i.e. one that returns a future) would improve on this by allowing it to return on a different thread than the one it was called on, because the code before and after the await are separate tasks. It would require running futures on the thread pool.

Is this something that has been explored before?

@cuviper
Copy link
Member

cuviper commented Aug 28, 2023

Asynchronous code is quite different from the user perspective, compared to Fn traits. It's not something we can just graft in automatically, but there have been experiments with futures if you search through issues. Alternatively, if you're concerned about such latency, have you considered using tokio's thread pool?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants