Struct rusty_pool::Builder
source · [−]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
sourceimpl Builder
impl Builder
sourcepub fn name(self, name: String) -> Builder
pub fn name(self, name: String) -> 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.
sourcepub fn core_size(self, size: usize) -> Builder
pub fn core_size(self, size: usize) -> Builder
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.
sourcepub fn max_size(self, size: usize) -> Builder
pub fn max_size(self, size: usize) -> Builder
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.
sourcepub fn keep_alive(self, keep_alive: Duration) -> Builder
pub fn keep_alive(self, keep_alive: Duration) -> Builder
Specify the duration for which additional threads outside the core pool remain alive while not receiving any work before giving up and terminating.
sourcepub fn build(self) -> ThreadPool
pub fn build(self) -> ThreadPool
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
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more