-
Notifications
You must be signed in to change notification settings - Fork 640
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
Waiting for threadpool threads to drop #1470
Comments
I tried just saving all the thread handles and joining them in drop, but this doesn't work. This is probably because the |
The behaviour I'm seeing is that futures are not dropped after the threadpool is dropped. |
// Let there be some shared data in an Arc
let shared_data = Arc::new(data);
// Let there be a future that has a strong reference to this data
let future = SomeFuture::new(shared_data.clone());
// Spawn it on the threadpool
threadpool.spawn(future);
// The threadpool Drop implementation has been patched to join every thread
drop(threadpool);
// Now all the threadpool threads are dropped
// So logically, we are the only owner of the shared data Arc now?
assert!(Arc::strong_count(&shared_data) == 1);
// PANIC!
// Replacing the assert with a while loop:
// Note that this actually returns after a very short time
while Arc::strong_count(&shared_data) != 1 {}
// Returns. |
I have created a P.o.C. threadpool that does not have this issue: https://github.com/PvdBerg1998/futures-executor |
Adds an option to ThreadPoolBuilder to configure the resulting ThreadPool to join the worker threads when dropped. fixes rust-lang#1470
I have some shared data in an
Arc
that I want to drop when my program exits.However, when I drop the
ThreadPool
, this only sends aClose
message to the worker threads but does not join them. This means I have no way to block until I know the threads/shared data is dropped.Edit: Tokio's threadpool does not have this issue.
The text was updated successfully, but these errors were encountered: