scoped_pool

Struct Pool

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn workers(&self) -> usize

How many worker threads are currently active.

Source

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.

Source

pub fn scoped<'scope, F, R>(&self, scheduler: F) -> R
where F: FnOnce(&Scope<'scope>) -> 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.

Source

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.

Source

pub fn expand(&self)

Expand the Pool by spawning an additional thread.

Can accelerate the completion of running jobs.

Trait Implementations§

Source§

impl Clone for Pool

Source§

fn clone(&self) -> Pool

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Pool

Source§

fn default() -> Pool

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Pool

§

impl !RefUnwindSafe for Pool

§

impl Send for Pool

§

impl Sync for Pool

§

impl Unpin for Pool

§

impl !UnwindSafe for Pool

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.