Crates.io | objpool |
lib.rs | objpool |
version | 0.2.0 |
source | src |
created_at | 2016-08-25 23:42:26.112739 |
updated_at | 2016-08-29 01:39:47.626357 |
description | Thread-safe generic object pool |
homepage | |
repository | https://github.com/btmorex/objpool |
max_upload_size | |
id | 6116 |
size | 11,427 |
Thread-safe generic object pool
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);