2 unstable releases

Uses old Rust 2015

0.2.0 Aug 29, 2016
0.1.0 Aug 25, 2016

#30 in #object-pool

Download history 1/week @ 2023-12-22 2/week @ 2024-01-05 11/week @ 2024-01-12 2/week @ 2024-01-19 2/week @ 2024-02-02 17/week @ 2024-02-09 19/week @ 2024-02-16 79/week @ 2024-02-23 34/week @ 2024-03-01 34/week @ 2024-03-08 24/week @ 2024-03-15 60/week @ 2024-03-22 75/week @ 2024-03-29 27/week @ 2024-04-05

189 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