Struct crossbeam::thread::ScopedJoinHandle
source · pub struct ScopedJoinHandle<'scope, T> { /* private fields */ }
Expand description
A handle that can be used to join its scoped thread.
Implementations§
source§impl<'scope, T> ScopedJoinHandle<'scope, T>
impl<'scope, T> ScopedJoinHandle<'scope, T>
sourcepub fn join(self) -> Result<T, Box<dyn Any + Send + 'static, Global>>
pub fn join(self) -> Result<T, Box<dyn Any + Send + 'static, Global>>
Waits for the thread to finish and returns its result.
If the child thread panics, an error is returned.
Panics
This function may panic on some platforms if a thread attempts to join itself or otherwise may create a deadlock with joining threads.
Examples
use crossbeam_utils::thread;
thread::scope(|s| {
let handle1 = s.spawn(|_| println!("I'm a happy thread :)"));
let handle2 = s.spawn(|_| panic!("I'm a sad thread :("));
// Join the first thread and verify that it succeeded.
let res = handle1.join();
assert!(res.is_ok());
// Join the second thread and verify that it panicked.
let res = handle2.join();
assert!(res.is_err());
}).unwrap();