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-11-27 4/week @ 2023-12-04 3/week @ 2023-12-18 3/week @ 2024-01-08 12/week @ 2024-01-15 5/week @ 2024-02-05 24/week @ 2024-02-12 13/week @ 2024-02-19 97/week @ 2024-02-26 21/week @ 2024-03-04 21/week @ 2024-03-11

154 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