Struct std::thread::Builder
[−]
[src]
pub struct Builder { // some fields omitted }
Thread configuration. Provides detailed control over the properties and behavior of new threads.
Methods
impl Builder
fn new() -> Builder
Generates the base configuration for spawning a thread, from which configuration methods can be chained.
fn name(self, name: String) -> Builder
Names the thread-to-be. Currently the name is used for identification only in panic messages.
fn stack_size(self, size: usize) -> Builder
Sets the size of the stack for the new thread.
fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>> where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
Spawns a new thread, and returns a join handle for it.
The child thread may outlive the parent (unless the parent thread is the main thread; the whole process is terminated when the main thread finishes). The join handle can be used to block on termination of the child thread, including recovering its panics.
Errors
Unlike the spawn
free function, this method yields an
io::Result
to capture any failure to create the thread at
the OS level.
fn scoped<'a, T, F>(self, f: F) -> Result<JoinGuard<'a, T>> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a
: memory unsafe if destructor is avoided, see #24292
Spawns a new child thread that must be joined within a given
scope, and returns a JoinGuard
.
The join guard can be used to explicitly join the child thread (via
join
), returning Result<T>
, or it will implicitly join the child
upon being dropped. Because the child thread may refer to data on the
current thread's stack (hence the "scoped" name), it cannot be detached;
it must be joined before the relevant stack frame is popped. See the
module documentation for additional details.
Errors
Unlike the scoped
free function, this method yields an
io::Result
to capture any failure to create the thread at
the OS level.