Struct poolio::ThreadPool

source ·
pub struct ThreadPool { /* private fields */ }
Expand description

Abstracts the thread-pools.

Implementations§

source§

impl ThreadPool

source

pub fn new<'a>(size: usize, mode: PanicSwitch) -> Result<Self, &'a str>

Sets up a new pool.

  • size is the (non-zero) number of worker-threads in the pool.
  • mode is the setting of the panic switch.
Errors

An error is returned if 0 was passed as size (since a pool without worker-threads does not make sense).

Examples

Setting up a pool with three worker-threads in kill-mode:

let pool = poolio::ThreadPool::new(3, poolio::PanicSwitch::Kill).unwrap();
source

pub fn execute<F>(&self, f: F)where F: FnOnce() + UnwindSafe + Send + 'static,

Runs a job in self.

  • f is the job to be run and has to be provided as a certain closure.

Note that if f panics, the behavior is according to the setting of the PanicSwitch of self.

Panics

A panic is caused if the pool is unreachable.

Examples

Setting up a pool and printing two strings concurrently:

let pool = poolio::ThreadPool::new(2, poolio::PanicSwitch::Kill).unwrap();
pool.execute(|| println!{"house"});
pool.execute(|| println!{"cat"});

Trait Implementations§

source§

impl Drop for ThreadPool

source§

fn drop(&mut self)

Tries to shut down self gracefully.

In particular, one has to assume that all remaining jobs will be finished (modulo panics in PanicSwitch::Kill-mode).

Panics

A panic occurs if

  1. the pool is unreachable
  2. joining the threads panics.

Remember that a panic while dropping aborts the whole process.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.