RB
Size: a a a
RB
p
ΑZ
ΑZ
ΑZ
ΑZ
RB
D
use crossbeam::thread;
fn main() {
thread::scope(|s| {
s.spawn(|_| {
let var = vec![3,2,1];
thread::scope(|s| {
s.spawn(|_| {
println!("A child thread borrowing `var`: {:?}", var);
});
panic!();
});
panic!();
});
}).unwrap();
}
thread '<unnamed>' panicked at 'explicit panic', src/main.rs:14:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Segmentation fault (core dumped)
D
pub fn scope<'env, F, R>(f: F) -> thread::Result<R>
where
F: FnOnce(&Scope<'env>) -> R,
{
let wg = WaitGroup::new();
let scope = Scope::<'env> {
handles: SharedVec::default(),
wait_group: wg.clone(),
_marker: PhantomData,
};
// Execute the scoped function, but catch any panics.
//let result = panic::catch_unwind(panic::AssertUnwindSafe(|| f(&scope)));
let result = f(&scope);
// Wait until all nested scopes are dropped.
drop(scope.wait_group);
wg.wait();
// Join all remaining spawned threads.
let panics: Vec<_> = scope
.handles
.lock()
.unwrap()
// Filter handles that haven't been joined, join them, and collect errors.
.drain(..)
.filter_map(|handle| handle.lock().unwrap().take())
.filter_map(|handle| handle.join().err())
.collect();
// If `f` has panicked, resume unwinding.
// If any of the child threads have panicked, return the panic errors.
// Otherwise, everything is OK and return the result of `f`.
/*match result {
Err(err) => panic::resume_unwind(err),
Ok(res) => {
if panics.is_empty() {
Ok(res)
} else {
Err(Box::new(panics))
}
}
}*/
Ok(result)
}
А
use crossbeam::thread;
fn main() {
thread::scope(|s| {
s.spawn(|_| {
let var = vec![3,2,1];
thread::scope(|s| {
s.spawn(|_| {
println!("A child thread borrowing `var`: {:?}", var);
});
panic!();
});
panic!();
});
}).unwrap();
}
thread '<unnamed>' panicked at 'explicit panic', src/main.rs:14:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Segmentation fault (core dumped)
D
RB
ΑZ
ΑZ
ΑZ
IN
RB
ΑZ
А
RB