Function crossbeam_utils::thread::scope

source ·
pub fn scope<'env, F, R>(f: F) -> Result<R>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. Note that if panics are implemented by aborting the process, no error is returned; see the notes of std::panic::catch_unwind.

Examples

use crossbeam_utils::thread;

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

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