scoped_stateful_threadpool

Crates.ioscoped_stateful_threadpool
lib.rsscoped_stateful_threadpool
version0.1.8
sourcesrc
created_at2017-10-22 10:25:17.849734
updated_at2017-10-22 10:25:17.849734
descriptionA library for scoped and cached threadpools that keep a state.
homepage
repositoryhttps://github.com/njaard/scoped-stateful-threadpool-rs
max_upload_size
id36543
size26,083
project-freta (github:microsoft:project-freta)

documentation

https://docs.rs/scoped_stateful_threadpool/

README

scoped-stateful-threadpool-rs

A library for scoped and cached threadpools that keep a state so that you don't need a connection pool.

Getting Started

scoped-threadpool-rs is available on crates.io. Add the following dependency to your Cargo manifest to get the latest version of the 0.1 branch:

[dependencies]

scoped_stateful_threadpool = "0.1.*"

To always get the latest version, add this git repository to your Cargo manifest:

[dependencies.scoped_stateful_threadpool]
git = "https://github.com/njaard/scoped-stateful-threadpool-rs"

Example

extern crate scoped_stateful_threadpool;
use scoped_stateful_threadpool::Pool;

fn main() {
    // Create a threadpool holding 4 threads
    let mut pool = Pool::new(4, &|| 0);

    let mut vec = vec![0, 1, 2, 3, 4, 5, 6, 7];

    // Use the threads as scoped threads that can
    // reference anything outside this closure
    pool.scoped(|scoped| {
        // Create references to each element in the vector ...
        for e in &mut vec {
            // ... and add 1 to it in a seperate thread
            scoped.execute(move |state| {
                *state += 1; // I can change the state
                *e += 1;
            });
        }
    });

    assert_eq!(vec, vec![1, 2, 3, 4, 5, 6, 7, 8]);
}
Commit count: 52

cargo fmt