Function thread_priority::spawn_scoped

source ·
pub fn spawn_scoped<'scope, 'env, F, T>(
    scope: &'scope Scope<'scope, 'env>,
    priority: ThreadPriority,
    f: F
) -> Result<ScopedJoinHandle<'scope, T>>
where F: FnOnce(Result<(), Error>) -> T + Send + 'scope, T: Send + 'scope,
Expand description

Spawns a scoped thread with the specified priority.

See ThreadBuilderExt::spawn_with_priority.

use thread_priority::*;

let x = 0;

std::thread::scope(|s| {
    spawn_scoped(s, ThreadPriority::Max, |result| {
        // This is printed out from within the spawned thread.
        println!("Set priority result: {:?}", result);
        assert!(result.is_ok());
        dbg!(&x);
    });
});