pub struct DispatchPoolBuilder { /* private fields */ }
Expand description
A builder for DispatchPool
supporting an extenstive set of
configuration options.
Implementations§
Source§impl DispatchPoolBuilder
impl DispatchPoolBuilder
Sourcepub fn new() -> DispatchPoolBuilder
pub fn new() -> DispatchPoolBuilder
Create new dispatch pool builder, for configuration.
Sourcepub fn pool_size(&mut self, size: usize) -> &mut Self
pub fn pool_size(&mut self, size: usize) -> &mut Self
Set the fixed number of threads in the pool.
This must at least be one (1) thread, asserted. However the value is ignored (and no threads are spawned) if queue_length is zero (0).
Default: the number of logical CPU’s minus one, but one at minimum:
Detected CPUs | Default Pool Size |
---|---|
0 | 1 |
1 | 1 |
2 | 1 |
3 | 2 |
4 | 3 |
Detected CPUs may be influenced by simultaneous multithreading (SMT, e.g. Intel hyper-threading) or scheduler affinity. Zero (0) detected CPUs is likely an error.
Sourcepub fn queue_length(&mut self, length: usize) -> &mut Self
pub fn queue_length(&mut self, length: usize) -> &mut Self
Set the length (aka maximum capacity or depth) of the associated dispatch task queue.
The length may be zero, in which case the pool is always considered
full and no threads are spawned. If the queue is ever full, the
oldest tasks will be executed on the calling thread, see
DispatchPool::spawn
.
Default: unbounded (unlimited)
Sourcepub fn ignore_panics(&mut self, ignore: bool) -> &mut Self
pub fn ignore_panics(&mut self, ignore: bool) -> &mut Self
Set whether to catch and ignore unwinds for dispatch tasks that panic, or to abort.
If true, panics are ignored. Note that the unwind safety of dispatched
tasks is not well assured by the UnwindSafe
marker trait and may
later result in undefined behavior (UB) or logic bugs.
If false, a panic in a dispatch pool thread will result in process abort.
Default: false
Sourcepub fn stack_size(&mut self, stack_size: usize) -> &mut Self
pub fn stack_size(&mut self, stack_size: usize) -> &mut Self
Set the stack size in bytes for each thread in the pool.
Default: the default thread stack size.
Sourcepub fn name_prefix<S: Into<String>>(&mut self, name_prefix: S) -> &mut Self
pub fn name_prefix<S: Into<String>>(&mut self, name_prefix: S) -> &mut Self
Set name prefix for threads in the pool.
The (unique) thread index is appended to form the complete thread name.
Default: “dpx-pool-N-” where N is a 0-based global pool counter.
Sourcepub fn after_start<F>(&mut self, f: F) -> &mut Self
pub fn after_start<F>(&mut self, f: F) -> &mut Self
Set a closure to be called immediately after each thread is started.
The closure is passed a 0-based index of the thread.
Default: None
Sourcepub fn before_stop<F>(&mut self, f: F) -> &mut Self
pub fn before_stop<F>(&mut self, f: F) -> &mut Self
Set a closure to be called immediately before a pool thread exits.
The closure is passed a 0-based index of the thread.
Default: None
Sourcepub fn create(&mut self) -> DispatchPool
pub fn create(&mut self) -> DispatchPool
Create a new DispatchPool
with the provided configuration.