[−][src]Struct blocking_permit::DispatchPool
A specialized thread pool and queue for dispatching blocking (synchronous, long running) operations.
This pool is not an executor, has no waking facilities, etc. As
compared with other thread pools supporting spawn_dispatch
(here called
just dispatch
), for example in tokio and async-std, this pool has
some unique features:
-
A configurable, fixed number of threads created before return from construction and terminated on
Drop::drop
. Consistent memory footprint. No warmup required. No per-task thread management overhead. -
Supports configuration for all crossbeam-channel MPMC queue options including fixed (bounded), including zero capacity, or an unbounded queue.
-
Configurable panic handling policy: Either catches and logs dispatch panics, or aborts the process, on panic unwind.
-
For comparative testing, can also be configured with zero (0) threads.
-
With zero threads or when the queue is bounded and becomes full,
DispatchPool::spawn
runs the provided task on the calling thread as a fallback. This is entirely optional and avoided with default settings of an unbounded queue and one or more threads. Its most useful for testing and benchmarking.
Usage
By default, the pool uses an unbounded MPMC channel, with the assumption
that resource/capacity is externally constrained, for example via
Semaphore
. Once constructed, a fixed number of
threads are spawned and the instance acts as a handle to the pool. This may
be inexpensively cloned for additional handles to the same pool.
See DispatchPoolBuilder
for an extensive set of options, some of which
are more appropriate for testing than production use.
Methods
impl DispatchPool
[src]
pub fn new() -> DispatchPool
[src]
Create new pool using defaults.
pub fn builder() -> DispatchPoolBuilder
[src]
Create a new builder for configuring a new pool.
pub fn spawn(&self, f: Box<dyn FnOnce() + Send>)
[src]
Enqueue a blocking operation to be executed.
This first attempts to send to the associated queue, which will always
succeed if unbounded, e.g. no DispatchPoolBuilder::queue_length
is set, the default. If however the queue is bounded and at capacity,
or the pool is configured with zero (pool_size
) threads, then the
task is directly run by the calling thread.
Trait Implementations
impl Clone for DispatchPool
[src]
fn clone(&self) -> DispatchPool
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for DispatchPool
[src]
impl Default for DispatchPool
[src]
Auto Trait Implementations
impl RefUnwindSafe for DispatchPool
impl Send for DispatchPool
impl Sync for DispatchPool
impl Unpin for DispatchPool
impl UnwindSafe for DispatchPool
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,