pub struct Pool { /* private fields */ }Expand description
A thread-pool providing scoped and unscoped threads.
The primary ways of interacting with the Pool are
the spawn and scoped convenience methods or through
the Scope type directly.
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn new(size: usize) -> Pool
pub fn new(size: usize) -> Pool
Create a new Pool with size threads.
If size is zero, no threads will be spawned. Threads can
be added later via expand.
NOTE: Since Pool can be freely cloned, it does not represent a unique
handle to the thread pool. As a consequence, the thread pool is not
automatically shut down; you must explicitly call Pool::shutdown to
shut down the pool.
Sourcepub fn with_thread_config(size: usize, thread_config: ThreadConfig) -> Pool
pub fn with_thread_config(size: usize, thread_config: ThreadConfig) -> Pool
Create a new Pool with size threads and given thread config.
If size is zero, no threads will be spawned. Threads can
be added later via expand.
NOTE: Since Pool can be freely cloned, it does not represent a unique
handle to the thread pool. As a consequence, the thread pool is not
automatically shut down; you must explicitly call Pool::shutdown to
shut down the pool.
Sourcepub fn empty() -> Pool
pub fn empty() -> Pool
Create an empty Pool, with no threads.
Note that no jobs will run until expand is called and
worker threads are added.
Sourcepub fn spawn<F: FnOnce() + Send + 'static>(&self, job: F)
pub fn spawn<F: FnOnce() + Send + 'static>(&self, job: F)
Spawn a 'static' job to be run on this pool.
We do not wait on the job to complete.
Panics in the job will propogate to the calling thread.
Sourcepub fn scoped<'scope, F, R>(&self, scheduler: F) -> R
pub fn scoped<'scope, F, R>(&self, scheduler: F) -> R
Create a Scope for scheduling a group of jobs in 'scope'.
scoped will return only when the scheduler function and
all jobs queued on the given Scope have been run.
Panics in any of the jobs or in the scheduler function itself will propogate to the calling thread.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shutdown the Pool.
WARNING: Extreme care should be taken to not call shutdown concurrently with any scoped calls, or deadlock can occur.
All threads will be shut down eventually, but only threads started before the call to shutdown are guaranteed to be shut down before the call to shutdown returns.