[][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 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.


use crossbeam_utils::thread;

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

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