[][src]Struct slave_pool::ThreadPool

pub struct ThreadPool { /* fields omitted */ }

Thread pool that allows to change number of threads at runtime.

On Drop it instructs threads to shutdown, but doesn't await for them to finish

Note

The pool doesn't implement any sort of flow control. If workers are busy, message will remain in queue until any other thread can take it.

Clone

Thread pool intentionally doesn't implement Clone If you want to share it, then share it by using global variable or on heap. It is thread safe, so concurrent access is allowed.

Panic

Each thread wraps execution of job into catch_unwind to ensure that thread is not aborted on panic

Implementations

impl ThreadPool[src]

pub const fn new() -> Self[src]

Creates new thread pool with default params

pub const fn with_defaults(name: &'static str, stack_size: usize) -> Self[src]

Creates new instance by specifying all params

pub fn set_stack_size(&self, stack_size: usize) -> usize[src]

Sets stack size to use.

By default it uses default value, used by Rust's stdlib. But setting this variable overrides it, allowing to customize it.

This setting takes effect only when creating new threads

pub fn set_threads(&self, thread_num: u16) -> Result<u16>[src]

Sets worker number, starting new threads if it is greater than previous

In case if it is less, extra threads are shut down. Returns previous number of threads.

By default when pool is created no threads are started.

If any thread fails to start, function returns immediately with error.

Note

Any calls to this method are serialized, which means under hood it locks out any attempt to change number of threads, until it is done

pub fn spawn<F: FnOnce() + Send + 'static>(&self, job: F)[src]

Schedules new execution, sending it over to one of the workers.

pub fn spawn_handle<R: Send + 'static, F: FnOnce() -> R + Send + 'static>(
    &self,
    job: F
) -> JobHandle<R>

Notable traits for JobHandle<T>

impl<T> Future for JobHandle<T> type Output = Result<T, JoinError>;
[src]

Schedules execution, that allows to await and receive it's result.

Trait Implementations

impl Debug for ThreadPool[src]

impl Sync for ThreadPool[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.