-
Notifications
You must be signed in to change notification settings - Fork 508
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
Consider adding an easier way of synchronously shutting down a thread-pool. #688
Comments
An existing option that should even solve your TLS is ThreadPoolBuilder::new().build_scoped(
|thread| thread.run(), // do other setup before running if you like
|pool| pool.install(work),
)?;
// threads will be totally gone here I think there's also room for something like |
Right, in this case I want a global thread pool that on shutdown I can wait on and drop, though, so I think build_scoped doesn't work. |
Ah, that's a harder one, and now I remember where I was playing with this before -- #483. |
I was working through a similar issue of needing to await all the threads in a Would using a |
Is this something that is still looked into? My use-case is a However, at some point I'm done feeding work into the pool, and Unfortunately there seems to be no such thing on Or is there perhaps another API that I'm missing that I might need? It basically feels like I need an |
You can save up the join handles like this: https://searchfox.org/mozilla-central/rev/146638366864f73ee8a697ea76480eb02c00eb3c/servo/components/style/global_style_data.rs#67 and then join them. |
@emilio thanks for pointing that out, but ouch. I was looking for something more out of the box, manually defining the |
You could wrap this in a Or you could use a If you're not doing anything else rayon-ish with these threads, then a plain
I would expect that the threads are still running after that drop, because there's no Rust way to interrupt a thread in progress, but if you exit the program then all threads will be terminated. |
@cuviper thanks, yeah that must be what's happening, because I'm "waiting" on these threads right before app exit (and if no-one waits on them, they'll get killed when the process exits). Indeed, |
AFAICT
ThreadPool::drop
is async, so there's no easy way to ensure that all threads have shot down.Ideally, I'd like the guarantee of all threads having shot down, including running TLS destructors, by the time
ThreadPool::drop
(or whatever API this would be) returns. This is so I can do deterministic leak-checking.I think you can do something using
exit_handler
plusstd::sync::Barrier
or something like that, but without the TLS-destructors-ran guarantee. That'd only guarantee that all pre-existing jobs have finished.cc @cuviper
The text was updated successfully, but these errors were encountered: