| Crates.io | concurrent-pool |
| lib.rs | concurrent-pool |
| version | 0.1.2 |
| created_at | 2025-09-21 14:07:35.515473+00 |
| updated_at | 2025-09-25 14:36:38.418073+00 |
| description | A concurrent object pool. |
| homepage | |
| repository | https://github.com/traceflight/concurrent-pool |
| max_upload_size | |
| id | 1848836 |
| size | 54,564 |
A concurrent object pool based on Crossbeam Queue
surplus-pull reaches a certain threshold if auto_reclaim is enabled.surplus-pull: After pulling data from the memory pool, available allocated
entities in the memory pool are exceed a certain threshold. We call this pull
is a surplus-pull.
use concurrent_pool::Pool;
let pool: Pool<u32> = Pool::with_capacity(10);
assert_eq!(pool.available(), 10);
let item = pool.pull().unwrap();
assert_eq!(*item, 0);
assert_eq!(pool.available(), 9);
let item_clone = item.clone();
drop(item);
assert_eq!(pool.available(), 9);
drop(item_clone);
assert_eq!(pool.available(), 10);
use concurrent_pool::{Pool, Builder};
use std::sync::{Arc, mpsc};
let mut builder = Builder::new();
let pool: Arc<Pool<String>> = Arc::new(builder.capacity(10).clear_func(String::clear).build());
let (tx, rx) = mpsc::channel();
let clone_pool = pool.clone();
let tx1 = tx.clone();
let sender1 = std::thread::spawn(move || {
let item = clone_pool.pull_owned_with(|x| x.push_str("1")).unwrap();
tx1.send((1, item)).unwrap();
});
let clone_pool = pool.clone();
let sender2 = std::thread::spawn(move || {
let item = clone_pool.pull_owned_with(|x| x.push_str("2")).unwrap();
tx.send((2, item)).unwrap();
});
let receiver = std::thread::spawn(move || {
for _ in 0..2 {
let (id, item) = rx.recv().unwrap();
if id == 1 {
assert_eq!(*item, "1");
} else {
assert_eq!(*item, "2");
}
}
});
sender1.join().unwrap();
sender2.join().unwrap();
receiver.join().unwrap();
This project is licensed under either of
at your option.