pub struct ThreadPool<T> { /* private fields */ }Expand description
Execute tasks on one of possibly several pooled threads.
For more details, see the library level documentation.
Implementations§
Source§impl<T: Task> ThreadPool<T>
impl<T: Task> ThreadPool<T>
Sourcepub fn fixed_size(size: usize) -> (Sender<T>, ThreadPool<T>)
pub fn fixed_size(size: usize) -> (Sender<T>, ThreadPool<T>)
Create a thread pool that reuses a fixed number of threads operating off a shared unbounded queue.
At any point, at most size threads will be active processing tasks. If
additional tasks are submitted when all threads are active, they will
wait in the queue until a thread is available. If any thread terminates
due to a failure during execution prior to the thread pool shutting
down, a new one will take its place if needed to execute subsequent
tasks. The threads in the pool will exist until the thread pool is
explicitly shutdown.
Sourcepub fn single_thread() -> (Sender<T>, ThreadPool<T>)
pub fn single_thread() -> (Sender<T>, ThreadPool<T>)
Create a thread pool with a single worker thread operating off an unbounded queue.
Note, however, that if this single thread termintaes due to a failure during execution prior to the thread pool shutting down, a new one will take its place if needed to execute subsequent tasks. Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time.
Sourcepub fn prestart_core_thread(&self) -> bool
pub fn prestart_core_thread(&self) -> bool
Start a core thread, causing it to idly wait for work.
This overrides the default policy of starting core threads only when new
tasks are executed. This function will return false if all core
threads have already been started.
Sourcepub fn prestart_core_threads(&self)
pub fn prestart_core_threads(&self)
Start all core threads, causing them to idly wait for work.
This overrides the default policy of starting core threads only when new tasks are executed.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Initiate an orderly shutdown.
Any previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if the thread pool has already been shut down.
This function will not wait for previously submitted tasks to complete
execution. Use await_termination to do that.
Sourcepub fn shutdown_now(&self)
pub fn shutdown_now(&self)
Shutdown the thread pool as fast as possible.
Worker threads will no longer receive tasks off of the work queue. This function will drain any remaining tasks before returning.
There are no guarantees beyond best-effort attempts to actually shutdown in a timely fashion. Threads will finish processing tasks that are currently running.
Sourcepub fn is_terminating(&self) -> bool
pub fn is_terminating(&self) -> bool
Returns true if the thread pool is in the process of terminating but
has not yet terminated.
Sourcepub fn is_terminated(&self) -> bool
pub fn is_terminated(&self) -> bool
Returns true if the thread pool is currently terminated.
Sourcepub fn await_termination(&self)
pub fn await_termination(&self)
Blocks the current thread until the thread pool has terminated