Struct std::sync::TaskPoolUnstable
[-] [+]
[src]
pub struct TaskPool { // 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
fn main() { use std::sync::TaskPool; use std::iter::AdditiveIterator; use std::sync::mpsc::channel; let pool = TaskPool::new(4); let (tx, rx) = channel(); for _ in 0..8 { let tx = tx.clone(); pool.execute(move|| { tx.send(1_u32).unwrap(); }); } assert_eq!(rx.iter().take(8).sum(), 8); }use std::sync::TaskPool; use std::iter::AdditiveIterator; use std::sync::mpsc::channel; let pool = TaskPool::new(4); let (tx, rx) = channel(); for _ in 0..8 { let tx = tx.clone(); pool.execute(move|| { tx.send(1_u32).unwrap(); }); } assert_eq!(rx.iter().take(8).sum(), 8);