Struct std::sync::TaskPoolExperimental [-]  [+] [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; let pool = TaskPool::new(4u); let (tx, rx) = channel(); for _ in range(0, 8u) { let tx = tx.clone(); pool.execute(move|| { tx.send(1u); }); } assert_eq!(rx.iter().take(8u).sum(), 8u); }

let pool = TaskPool::new(4u);

let (tx, rx) = channel();
for _ in range(0, 8u) {
    let tx = tx.clone();
    pool.execute(move|| {
        tx.send(1u);
    });
}

assert_eq!(rx.iter().take(8u).sum(), 8u);

Methods

impl TaskPool

fn new(threads: uint) -> TaskPool

Spawns a new thread pool with threads threads.

Panics

This function will panic if threads is 0.

fn execute<F>(&self, job: F) where F: FnOnce(), F: Send

Executes the function job on a thread in the pool.