Struct blocking_pool::ThreadPool [−][src]
pub struct ThreadPool { /* fields omitted */ }
A thread pool.
This can be cheaply cloned to create more handles to the same thread pool, so there is no need
to wrap it in an Arc
or similar type.
When dropped, the destructor won’t block but the thread pool itself will continue to run and
process tasks. You can call ThreadPool::wait_all_complete
to wait for all the active tasks
to complete.
Implementations
impl ThreadPool
[src]
#[must_use]pub fn new() -> Self
[src]
Construct a new thread pool using the default configuration. See Builder
for how to
customize it further.
#[must_use]pub fn builder() -> Builder
[src]
Create a Builder
for customizing a thread pool.
pub unsafe fn spawn_raw<T>(&self, data: *const T, run: unsafe fn(_: *const T))
[src]
Raw API for spawning a function on the thread pool.
This will call the given function pointer with the provided data
pointer on the blocking
thread pool at some point in the future.
Safety
When called with the provided data pointer from another thread, the run
function must not
cause UB or panic.
pub fn spawn_boxed<F: FnOnce() + Send + 'static>(&self, f: Box<F>)
[src]
Spawn a boxed closure on the thread pool.
Examples
let pool = blocking_pool::ThreadPool::new(); pool.spawn_boxed(Box::new(|| println!("Hello world")));
pub fn wait_all_complete(&self)
[src]
Wait for all the running and queued tasks in the thread pool to complete.
Examples
use std::time::{Duration, Instant}; let pool = blocking_pool::ThreadPool::new(); pool.spawn_boxed(Box::new(|| std::thread::sleep(Duration::from_secs(3)))); let start = Instant::now(); pool.wait_all_complete(); assert!(start.elapsed().as_secs() >= 3);
pub fn prune(&self)
[src]
Prune unused threads. These threads would time out and exit eventually of their own accord if they are not receiving any work, but this will force them to exit early.
Examples
let pool = blocking_pool::ThreadPool::new(); // This will start up a thread that will linger around even after the task is finished. pool.spawn_boxed(Box::new(|| {})); // This will forcibly kill that thread. pool.prune();
Trait Implementations
impl Clone for ThreadPool
[src]
fn clone(&self) -> ThreadPool
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ThreadPool
[src]
impl Default 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,
pub 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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,