pub struct Builder { /* private fields */ }
Expand description

A helper struct to aid creating a new ThreadPool using default values where no value was explicitly specified.

Implementations

Create a new Builder.

Specify the name of the ThreadPool that will be used as prefix for the name of each worker thread. By default the name is “rusty_pool_x” with x being a static pool counter.

Specify the core pool size for the ThreadPool. The core pool size is the number of threads that stay alive for the entire lifetime of the ThreadPool or, to be more precise, its channel. These threads are spawned if a task is submitted to the ThreadPool and the current worker count is below the core pool size.

Specify the maximum pool size this ThreadPool may scale up to. This numbers represents the maximum number of threads that may be alive at the same time within this pool. Additional threads above the core pool size only remain idle for the duration specified by the keep_alive parameter before terminating. If the core pool is full, the current pool size is below the max size and there are no idle threads then additional threads will be spawned.

Specify the duration for which additional threads outside the core pool remain alive while not receiving any work before giving up and terminating.

Build the ThreadPool using the parameters previously supplied to this Builder using the number of CPUs as default core size if none provided, twice the core size as max size if none provided, 60 seconds keep_alive if none provided and the default naming (rusty_pool_{pool_number}) if none provided. This function calls ThreadPool::new or ThreadPool::new_named depending on whether a name was provided.

Panics

Building might panic if the max_size is 0 or lower than core_size or exceeds half the size of usize. This restriction exists because two counters (total workers and idle counters) are stored within one AtomicUsize.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.