std::thread::Builder
Struct std::thread::Builder
pub struct Builder { /* fields omitted */ }
Thread configuration. Provides detailed control over the properties and behavior of new threads.
Examples
use std::thread; let builder = thread::Builder::new(); let handler = builder.spawn(|| { // thread code }).unwrap(); handler.join().unwrap();
Methods
impl Builder
[src]
fn new() -> Builder
Generates the base configuration for spawning a thread, from which configuration methods can be chained.
Examples
use std::thread; let builder = thread::Builder::new() .name("foo".into()) .stack_size(10); let handler = builder.spawn(|| { // thread code }).unwrap(); handler.join().unwrap();
fn name(self, name: String) -> Builder
Names the thread-to-be. Currently the name is used for identification only in panic messages.
Examples
use std::thread; let builder = thread::Builder::new() .name("foo".into()); let handler = builder.spawn(|| { assert_eq!(thread::current().name(), Some("foo")) }).unwrap(); handler.join().unwrap();
fn stack_size(self, size: usize) -> Builder
Sets the size of the stack (in bytes) for the new thread.
The actual stack size may be greater than this value if the platform specifies minimal stack size.
Examples
use std::thread; let builder = thread::Builder::new().stack_size(32 * 1024);
fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>> where
F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
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.
Examples
use std::thread; let builder = thread::Builder::new(); let handler = builder.spawn(|| { // thread code }).unwrap(); handler.join().unwrap();
Trait Implementations
impl Debug for Builder
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
Formats the value using the given formatter.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/struct.Builder.html