pub struct ThreadPool { /* fields omitted */ }
Create a new ThreadPool.
use sync_threadpool::ThreadPool;
let pool = ThreadPool::new(4);
Wait for all workers to be idle.
Submit a job to the threadpool. This method blocks until a worker becomes idle.
Submit a job to the threadpool. This method is nonblocking, if no worker is idle, it will
Return an error.
use std::sync::{Arc, Barrier};
use sync_threadpool::ThreadPool;
let mut pool = ThreadPool::new(2);
let barrier = Arc::new(Barrier::new(3));
let b1 = barrier.clone();
let b2 = barrier.clone();
pool.try_execute(move || {
b1.wait();
}).unwrap();
pool.try_execute(move || {
b2.wait();
}).unwrap();
pool.try_execute(move || {}).unwrap_err();
barrier.wait();
pool.wait_for_all();
pool.try_execute(move || {}).unwrap();
Executes the destructor for this type. Read more