Skip to main content

ThreadPool

Struct ThreadPool 

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

Thread pool for executing work in parallel

This matches the C++ thread_pool class with similar functionality:

  • Fixed number of worker threads
  • Work queue
  • Parallel for loop support

Implementations§

Source§

impl ThreadPool

Source

pub fn new(nthreads: usize) -> Self

Create a new thread pool with the specified number of threads

Source

pub fn submit<F, R, Args>(&self, f: F, args: Args) -> Receiver<R>
where F: FnOnce(Args) -> R + Send + 'static, R: Send + 'static, Args: Send + 'static,

Submit a function to be executed by the thread pool

Returns a receiver that can be used to get the result

Source

pub fn parallel_for<F>(&self, start: usize, end: usize, stride: usize, f: F)
where F: Fn(usize, usize, usize) + Send + Sync + Clone + 'static,

Execute a parallel for loop over a range

This matches the C++ thread_pool::parallel_for method

Source

pub fn size(&self) -> usize

Get the number of threads in the pool

Source

pub fn is_done(&self) -> bool

Check if the pool has been shut down

Trait Implementations§

Source§

impl Drop for ThreadPool

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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, 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.