[][src]Module executors::threadpool_executor

A thread pool Executor used to execute functions in parallel.

This implementation is simply a wrapper for threadpool to allow it to be used where the Executor trait is expected.

Examples

Synchronized with a channel

Every thread sends one message over the channel, which then is collected with the take().

use executors::*;
use executors::threadpool_executor::ThreadPoolExecutor;
use std::sync::mpsc::channel;

let n_workers = 4;
let n_jobs = 8;
let pool = ThreadPoolExecutor::new(n_workers);

let (tx, rx) = channel();
for _ in 0..n_jobs {
    let tx = tx.clone();
    pool.execute(move|| {
        tx.send(1).expect("channel will be there waiting for the pool");
    });
}

assert_eq!(rx.iter().take(n_jobs).fold(0, |a, b| a + b), 8);

Structs

ThreadPoolExecutor