pub struct ThreadPool { /* private fields */ }Expand description
A basic Thread Pool
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Create a new ThreadPool.
Sourcepub fn enqueue(&mut self, worker: impl Worker)
pub fn enqueue(&mut self, worker: impl Worker)
Enqueue a Worker to the ThreadPool.
Sourcepub fn update_threads(&mut self) -> bool
pub fn update_threads(&mut self) -> bool
Removes threads from the pool once they’re finished and spawn new ones from the queue.
Returns true if the pool is empty even after emptying the queue.
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Gets the capacity of the ThreadPool.
Sourcepub fn queued_count(&self) -> usize
pub fn queued_count(&self) -> usize
Returns the amount of enqueued Workers.
Sourcepub const fn active_count(&self) -> usize
pub const fn active_count(&self) -> usize
Returns the amount of running threads.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true when both the queue and pool are empty.
Auto Trait Implementations§
impl Freeze for ThreadPool
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl !Sync for ThreadPool
impl Unpin 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