ThreadPool

Struct ThreadPool 

Source
pub struct ThreadPool { /* private fields */ }
Expand description

A thread pool intended to run CPU intensive work.

This thread pool will hand out futures representing the completed work that happens on the thread pool itself, and the futures can then be later composed with other work as part of an overall computation.

The worker threads associated with a thread pool are kept alive so long as there is an open handle to the ThreadPool or there is work running on them. Once all work has been drained and all references have gone away the worker threads will be shut down.

Currently ThreadPool implements Clone which just clones a new reference to the underlying thread pool.

Note: if you use ThreadPool inside a library it’s better accept a Builder object for thread configuration rather than configuring just pool size. This not only future proof for other settings but also allows user to attach monitoring tools to lifecycle hooks.

Implementations§

Source§

impl ThreadPool

Source

pub fn new(size: usize) -> ThreadPool

Creates a new thread pool with size worker threads associated with it.

The returned handle can use execute to run work on this thread pool, and clones can be made of it to get multiple references to the same thread pool.

This is a shortcut for:

Builder::new().pool_size(size).create()
Source

pub fn new_num_cpus() -> ThreadPool

Creates a new thread pool with a number of workers equal to the number of CPUs on the host.

This is a shortcut for:

Builder::new().create()

Trait Implementations§

Source§

impl Clone for ThreadPool

Source§

fn clone(&self) -> ThreadPool

Returns a duplicate 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 Drop for ThreadPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Spawn<T> for ThreadPool
where T: Future<Item = (), Error = ()> + Send + 'static,

Source§

fn spawn_detached(&self, f: T)

Spawns a future to run on this Spawn. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> SpawnHelper for T

Source§

fn spawn<F>( &self, future: F, ) -> SpawnHandle<<F as Future>::Item, <F as Future>::Error>
where F: Future, Self: Spawn<Spawned<F>>,

Spawns a future to run on this Spawn, returning a future representing the produced value. Read more
Source§

fn spawn_fn<F, R>( &self, f: F, ) -> SpawnHandle<<R as IntoFuture>::Item, <R as IntoFuture>::Error>
where F: FnOnce() -> R, R: IntoFuture, Self: Spawn<Spawned<Lazy<F, R>>>,

Spawns a closure on this Spawn Read more
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.