pub struct ScopedThreadBuilder<'scope, 'env: 'scope> { /* fields omitted */ }
Configures the properties of a new thread.
The two configurable properties are:
The spawn
method will take ownership of the builder and return an io::Result
of the
thread handle with the given configuration.
The Scope::spawn
method uses a builder with default configuration and unwraps its return
value. You may want to use this builder when you want to recover from a failure to launch a
thread.
use crossbeam_utils::thread;
thread::scope(|s| {
s.builder()
.spawn(|_| println!("Running a child thread"))
.unwrap();
}).unwrap();
Sets the name for the new thread.
The name must not contain null bytes. For more information about named threads, see
here.
use crossbeam_utils::thread;
use std::thread::current;
thread::scope(|s| {
s.builder()
.name("my thread".to_string())
.spawn(|_| assert_eq!(current().name(), Some("my thread")))
.unwrap();
}).unwrap();
Sets the size of the stack for the new thread.
The stack size is measured in bytes.
use crossbeam_utils::thread;
thread::scope(|s| {
s.builder()
.stack_size(32 * 1024)
.spawn(|_| println!("Running a child thread"))
.unwrap();
}).unwrap();
Spawns a scoped thread with this configuration.
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.builder()
.spawn(|_| {
println!("A child thread is running");
42
})
.unwrap();
let res = handle.join().unwrap();
assert_eq!(res, 42);
}).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
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
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
)
Mutably borrows from an owned value. Read more