2 unstable releases

Uses old Rust 2015

0.2.0 Aug 29, 2016
0.1.0 Aug 25, 2016

#33 in #object-pool

45 downloads per month
Used in 3 crates (2 directly)

MIT license

9KB
228 lines

objpool

Thread-safe generic object pool

Build Status Coverage Status

Examples

use objpool::Pool;
use std::thread;

let pool = Pool::with_capacity(5, || 0);
let mut handles = Vec::new();
for _ in 0..10 {
    let pool = pool.clone();
    handles.push(thread::spawn(move || {
        for _ in 0..1000 {
            *pool.get() += 1;
        }
    }));
}

for handle in handles {
    handle.join().unwrap();
}
assert_eq!(*pool.get() + *pool.get() + *pool.get() + *pool.get() + *pool.get(), 10000);

lib.rs:

Examples

use objpool::Pool;
use std::thread;

let pool = Pool::with_capacity(5, || 0);
let mut handles = Vec::new();
for _ in 0..10 {
    let pool = pool.clone();
    handles.push(thread::spawn(move || {
        for _ in 0..1000 {
            *pool.get() += 1;
        }
    }));
}

for handle in handles {
    handle.join().unwrap();
}
assert_eq!(*pool.get() + *pool.get() + *pool.get() + *pool.get() + *pool.get(), 10000);

No runtime deps