[][src]Struct threadpool::Builder

pub struct Builder { /* fields omitted */ }

ThreadPool factory, which can be used in order to configure the properties of the ThreadPool.

The three configuration options available:

Examples

Build a ThreadPool that uses a maximum of eight threads simultaneously and each thread has a 8 MB stack size:

let pool = threadpool::Builder::new()
    .num_threads(8)
    .thread_stack_size(8_000_000)
    .build();

Methods

impl Builder[src]

pub fn new() -> Builder[src]

Initiate a new Builder.

Examples

let builder = threadpool::Builder::new();

pub fn num_threads(self, num_threads: usize) -> Builder[src]

Set the maximum number of worker-threads that will be alive at any given moment by the built ThreadPool. If not specified, defaults the number of threads to the number of CPUs.

Panics

This method will panic if num_threads is 0.

Examples

No more than eight threads will be alive simultaneously for this pool:

use std::thread;

let pool = threadpool::Builder::new()
    .num_threads(8)
    .build();

for _ in 0..100 {
    pool.execute(|| {
        println!("Hello from a worker thread!")
    })
}

pub fn thread_name(self, name: String) -> Builder[src]

Set the thread name for each of the threads spawned by the built ThreadPool. If not specified, threads spawned by the thread pool will be unnamed.

Examples

Each thread spawned by this pool will have the name "foo":

use std::thread;

let pool = threadpool::Builder::new()
    .thread_name("foo".into())
    .build();

for _ in 0..100 {
    pool.execute(|| {
        assert_eq!(thread::current().name(), Some("foo"));
    })
}

pub fn build(self) -> ThreadPool[src]

Finalize the Builder and build the ThreadPool.

Examples

let pool = threadpool::Builder::new()
    .num_threads(8)
    .thread_stack_size(4_000_000)
    .build();

Trait Implementations

impl Clone for Builder[src]

impl Default for Builder[src]

Auto Trait Implementations

impl RefUnwindSafe for Builder

impl Send for Builder

impl Sync for Builder

impl Unpin for Builder

impl UnwindSafe for Builder

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.