Struct threadpool::ThreadPool
[−]
[src]
pub struct ThreadPool { // some fields omitted }
A thread pool used to execute functions in parallel.
Spawns n
worker threads and replenishes the pool if any worker threads
panic.
Example
use threadpool::ThreadPool; use std::sync::mpsc::channel; let pool = ThreadPool::new(4); let (tx, rx) = channel(); for i in 0..8 { let tx = tx.clone(); pool.execute(move|| { tx.send(i).unwrap(); }); } assert_eq!(rx.iter().take(8).fold(0, |a, b| a + b), 28);
Methods
impl ThreadPool
fn new(threads: usize) -> ThreadPool
fn execute<F>(&self, job: F) where F: FnOnce() + Send + 'static
Executes the function job
on a thread in the pool.
fn active_count(&self) -> usize
Returns the number of currently active threads.
fn max_count(&self) -> usize
Returns the number of created threads
fn set_threads(&mut self, threads: usize)
Sets the number of threads to use as threads
.
Can be used to change the threadpool size during runtime