WorkersPool

Struct WorkersPool 

Source
pub struct WorkersPool<W: Worker> { /* private fields */ }
Expand description

Abstraction of a threadpool for executing units of computation in parallel.

Implementations§

Source§

impl<W: Worker> WorkersPool<W>

Source

pub fn new(context: W::Context) -> Self

Source

pub fn add_work(&mut self, work: W::Data) -> Result<(), ()>

Adds work to be executed on one of the threads of this pool This function is non-blocking

Source

pub fn receive_result(&mut self) -> Result<W::Result, ()>

Receives the result of a computation This function blocks until a result is available or all threads have panicked

Source

pub fn try_receive_result(&mut self) -> Result<Option<W::Result>, ()>

Tries to receive the result of a computation This function does not block if no result is available but rather returns Ok(None)

Source

pub fn collect_finished(&mut self) -> Result<Vec<W::Result>, ()>

Collects all available results

Source

pub fn has_work_left(&self) -> bool

Checks if any work is left in the work queue

Note: An empty work queue does not mean that none of the worker threads is still busy

Source

pub fn has_results(&self) -> bool

Checks if there are results available

Auto Trait Implementations§

§

impl<W> Freeze for WorkersPool<W>

§

impl<W> !RefUnwindSafe for WorkersPool<W>

§

impl<W> Send for WorkersPool<W>

§

impl<W> Sync for WorkersPool<W>

§

impl<W> Unpin for WorkersPool<W>
where <W as Worker>::Result: Unpin,

§

impl<W> !UnwindSafe for WorkersPool<W>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.