pub struct ThreadPool { /* private fields */ }Expand description
A thread pool for executing blocking operations.
The pool can be configured as either bounded or unbounded, which determines how tasks are handled when all worker threads are busy.
The number of worker threads scales dynamically with load, but will
never exceed the thread_limit parameter. When all worker threads are
busy, tasks are queued until a worker thread becomes available.
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(name: &str, thread_limit: usize, recv_timeout: Duration) -> Self
pub fn new(name: &str, thread_limit: usize, recv_timeout: Duration) -> Self
Creates a ThreadPool with a maximum number of worker threads
and a timeout for receiving tasks from the task channel.
A thread_limit of zero is treated as one.
Sourcepub fn execute<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
pub fn execute<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
Submits a closure to the thread pool.
The task will be executed by an available worker thread. If no threads are available and the pool has reached its maximum size, the work will be queued until a worker thread becomes available. This method never blocks.
Trait Implementations§
Source§impl Clone for ThreadPool
impl Clone for ThreadPool
Source§fn clone(&self) -> ThreadPool
fn clone(&self) -> ThreadPool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more