Struct sync_threadpool::ThreadPool[][src]

pub struct ThreadPool { /* fields omitted */ }

This is the thread pool.

Methods

impl ThreadPool
[src]

Create a new ThreadPool.

Example

use sync_threadpool::ThreadPool;

let pool = ThreadPool::new(4);

Wait for all workers to be idle.

Submit a job to the threadpool. This method blocks until a worker becomes idle.

Submit a job to the threadpool. This method is nonblocking, if no worker is idle, it will Return an error.

Example

use std::sync::{Arc, Barrier};
use sync_threadpool::ThreadPool;

let mut pool = ThreadPool::new(2);
let barrier = Arc::new(Barrier::new(3));
let b1 = barrier.clone();
let b2 = barrier.clone();

pool.try_execute(move || {
    b1.wait();
}).unwrap();
pool.try_execute(move || {
    b2.wait();
}).unwrap();

pool.try_execute(move || {}).unwrap_err();

barrier.wait();
pool.wait_for_all();

pool.try_execute(move || {}).unwrap();

Trait Implementations

impl Drop for ThreadPool
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for ThreadPool

impl !Sync for ThreadPool