Function crossbeam::scope[][src]

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

Creates a new scope for spawning threads.

All child threads that haven’t been manually joined will be automatically joined just before this function invocation ends. If all joined threads have successfully completed, Ok is returned with the return value of f. If any of the joined threads has panicked, an Err is returned containing errors from panicked threads.

Examples

use crossbeam_utils::thread;

let var = vec![1, 2, 3];

thread::scope(|s| {
    s.spawn(|_| {
        println!("A child thread borrowing `var`: {:?}", var);
    });
}).unwrap();