-
Notifications
You must be signed in to change notification settings - Fork 482
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
Change panic handling in scoped thread #844
Conversation
4f1b0cc
to
1aca853
Compare
BTW, in addition to this, I'm considering porting the rust-lang/rust#94559's changes to crossbeam. |
This implementation introduces a soundness bug, since the WaitGroup is dropped before the result of a thread (which might still borrow things) is dropped: use std::{thread::sleep, time::Duration};
struct PrintOnDrop<'a>(&'a str);
impl Drop for PrintOnDrop<'_> {
fn drop(&mut self) {
sleep(Duration::from_millis(100));
println!("{}", self.0);
}
}
fn main() {
let a = "hello".to_string();
let r = &a;
crossbeam::scope(|s| {
s.spawn(move |_| PrintOnDrop(r));
});
drop(a);
sleep(Duration::from_millis(200));
}
|
1aca853
to
e637a68
Compare
@m-ou-se Thanks! I pushed a fix for that bug EDIT: The fix is:
The last one is needed to properly handle cases where handles are not dropped: - s.spawn(move |_| X(actually_finished));
+ s.spawn(move |s| mem::forget(s.spawn(move |_| X(actually_finished)))); |
e637a68
to
f65a8db
Compare
bors r+ |
bors r- miri failed due to thread leaks: https://github.com/crossbeam-rs/crossbeam/runs/7479452681?check_suite_focus=true |
Canceled. |
f65a8db
to
b8a7160
Compare
- Panic instead of returning result - Do not own join handles in main thread
b8a7160
to
1c8635d
Compare
TODO: if we don't do #844 (comment), we probably shouldn't change the signature of scope function.
Fixes #816
Closes #724