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

Block until all rayon::spawn have completed #650

Open
gyscos opened this issue Mar 26, 2019 · 5 comments
Open

Block until all rayon::spawn have completed #650

gyscos opened this issue Mar 26, 2019 · 5 comments

Comments

@gyscos
Copy link

gyscos commented Mar 26, 2019

Until we have a way to parallelize a generic non-Send iterator, I'm using rayon::spawn from a single-threaded loop.
This works, except that the main thread will not wait for the tasks to complete before exiting.
Is there a way to block until all global tasks have been completed? Or should I maintain my own completion count for that?

@cuviper
Copy link
Member

cuviper commented Mar 26, 2019

We don't currently have a way to wait for idle, but I think we probably should.

@wagnerf42
Copy link
Contributor

how about using a scope ?

@cuviper
Copy link
Member

cuviper commented Mar 27, 2019

Indeed, a scope will not return until all of its Scope::spawns have completed. However, it does require that the initial closure is Send (#562), so @gyscos would have to create their non-Send iterator from within. And since this consumes one thread of the pool, you probably want to make sure there are more threads to do the spawned work, otherwise the whole iterator will be processed before getting to the spawns.

@gsquire
Copy link
Contributor

gsquire commented Apr 2, 2019

Perhaps you could leverage a WaitGroup?

@cuviper
Copy link
Member

cuviper commented Apr 25, 2022

Note: we do have in_place_scope now, without Send, so you can spawn tasks from the current thread and have a well-defined wait at the end of that scope.

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

4 participants