Struct jobpool::JobPool [] [src]

pub struct JobPool { /* fields omitted */ }

JobPool manages a job queue to be run on a specified number of threads.

Methods

impl JobPool
[src]

[src]

Creates a new job pool.

Using the number of cpu cores as argument for size is recommended. Higher values can result in larger memory footprint, and non-optimal performance.

Panics

This function will panic if the argument for size is 0.

Examples

use jobpool::JobPool;

let pool_size: usize = 8; // number of cpu cores is recommended
let mut pool = JobPool::new(pool_size);
pool.queue(|| {
    // do some work
});
// ...
pool.shutdown(); // blocks until all jobs are done

[src]

Queues a new "job".

A queued job gets run in a first-come, first-serve basis.

Panics

This method will panic if the JobPool instance has already been shutdown.

Examples

use jobpool::JobPool;

let pool_size: usize = 8; // number of cpu cores is recommended
let mut pool = JobPool::new(pool_size);
pool.queue(|| {
    // do some work
});
// ...
pool.shutdown(); // blocks until all jobs are done

[src]

Shuts down this instance of JobPool.

This method will wait for all of the queued jobs to finish. It also gets called automatically as the instance goes out of scope, so calling this method can be optional.

Examples

use jobpool::JobPool;

let pool_size: usize = 8; // number of cpu cores is recommended
let mut pool = JobPool::new(pool_size);
pool.queue(|| {
    // do some work
});
// ...
pool.shutdown(); // blocks until all jobs are done

[src]

Shuts down this instance of JobPool without waiting for threads to finish.

This method will return all of the threads' JoinHandles. It won't wait for the threads to finish, and it must be called explicitly. Calling shutdown() after this method won't have any effect. Unlike shutdown(), it doesn't get called automatically after going out of scope.

Examples

use jobpool::JobPool;

let pool_size: usize = 8; // number of cpu cores is recommended
let mut pool = JobPool::new(pool_size);
pool.queue(|| {
    // do some work
});
// ...
let handles = pool.shutdown_no_wait();
// ...
if let Some(handles) = handles {
    for handle in handles {
        let _ = handle.join();
    }
}

Trait Implementations

impl Drop for JobPool
[src]

[src]

Executes the destructor for this type. Read more