Skip to content

is using task::spawn_blocking for cpu bound tasks adviced? #752

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

Closed
jannickj opened this issue Apr 22, 2020 · 1 comment
Closed

is using task::spawn_blocking for cpu bound tasks adviced? #752

jannickj opened this issue Apr 22, 2020 · 1 comment

Comments

@jannickj
Copy link

The documentation says it will be given its own thread from a special threadpool, and that it's designed for long running blocking code. Is there any reason why we can't use this for CPU heavy tasks or is there something that might make this a bad idea?

@jimblandy
Copy link
Contributor

jimblandy commented Nov 4, 2020

Yes, if you have a CPU-bound task, or any sort of task where polling its future may take a long time, that's the case spawn_blocking is intended to serve.

However, there's a bit of uncertainty around this. The async-std blog had an article talking about how you can just use spawn for everything, and the runtime will dynamically detect if it blocks for a long time, and let it have that thread for its exclusive use. But I'm told that that strategy may be on hold.

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