[−][src]Struct slave_pool::ThreadPool
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.
Panic
Each thread wraps execution of job into catch_unwind
to ensure that thread is not aborted
on panic
Methods
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>
[src]
&self,
job: F
) -> JobHandle<R>
Schedules execution, that allows to await and receive it's result.
Trait Implementations
impl Debug for ThreadPool
[src]
impl Drop for ThreadPool
[src]
Auto Trait Implementations
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,