pub struct Scope<'env> { /* fields omitted */ }
A scope for spawning threads.
Spawns a scoped thread.
This method is similar to the spawn
function in Rust's standard library. The difference
is that this thread is scoped, meaning it's guaranteed to terminate before the scope exits,
allowing it to reference variables outside the scope.
The scoped thread is passed a reference to this scope as an argument, which can be used for
spawning nested threads.
The returned handle can be used to manually join the thread before the scope exits.
use crossbeam_utils::thread;
thread::scope(|s| {
let handle = s.spawn(|_| {
println!("A child thread is running");
42
});
let res = handle.join().unwrap();
assert_eq!(res, 42);
}).unwrap();
Creates a builder that can configure a thread before spawning.
use crossbeam_utils::thread;
use std::thread::current;
thread::scope(|s| {
s.builder()
.spawn(|_| println!("A child thread is running"))
.unwrap();
}).unwrap();
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static