[][src]Function crossbeam::scope

pub fn scope<'env, F, R>(f: F) -> Result<R, Box<dyn Any + 'static + Send>> where
    F: FnOnce(&Scope<'env>) -> R, 

Creates a new Scope for scoped thread spawning.

No matter what happens, before the Scope is dropped, it is guaranteed that all the unjoined spawned scoped threads are joined.

thread::scope() returns Ok(()) if all the unjoined spawned threads did not panic. It returns Err(e) if one of them panics with e. If many of them panic, it is still guaranteed that all the threads are joined, and thread::scope() returns Err(e) with e from a panicking thread.

Examples

Creating and using a scope:

crossbeam_utils::thread::scope(|scope| {
    scope.spawn(|_| println!("Exiting scope"));
    scope.spawn(|_| println!("Running child thread in scope"));
}).unwrap();