jlizard-simple-threadpool-0.2.1 has been yanked.
Simple threadpool
My own implementation of The Rust programming langauge official book implementation of a threadpool.
Features
- Configurable pool size (single-threaded, multi-threaded, or auto-detect)
- Graceful shutdown with job completion guarantees
- Worker signaling - jobs can signal all workers to stop via
Arc<AtomicBool>
Usage
Basic Example
use ThreadPool;
// let pool = ThreadPool::new(4); // 4 workers, or 0 for auto-detect, 1 for single-threaded
let pool = default; // runs the pool while auto detecting maximum threads
pool.execute.expect;
Worker Signaling (Early Termination)
For scenarios like hash collision detection where one worker should stop all others:
use ThreadPool;
use ;
let pool = new;
for i in 0..1000
Or check the signal within jobs:
use ThreadPool;
let pool = default;
let kill_signal = pool.get_kill_signal;
pool.execute.unwrap;
API
new(size: u8)- Create pool (0=auto, 1=single-threaded, N=N workers)execute<F>(&self, f: F)- Execute jobsignal_stop(&self)- Signal all workers to stop after current jobget_kill_signal(&self)- GetArc<AtomicBool>to check/set from jobsis_single_threaded(&self)- Check if single-threaded mode