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.
- In a bounded pool, submitting a task will fail if the number of concurrent operations has reached the thread limit.
- In an unbounded pool, tasks are queued and will wait until a worker thread becomes available.
The number of worker threads scales dynamically with load, but will
never exceed the thread_limit parameter.
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.
Sourcepub fn execute<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
pub fn execute<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
Submits a task (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.
Trait Implementations§
Source§impl Clone for ThreadPool
impl Clone for ThreadPool
Source§fn clone(&self) -> ThreadPool
fn clone(&self) -> ThreadPool
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ThreadPool
impl RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl UnsafeUnpin for ThreadPool
impl UnwindSafe for ThreadPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more