[][src]Crate lockfree_object_pool

A thread-safe object pool collection with automatic return.

Some implementations are lockfree :

Other use std::Mutex :

And NoneObjectPool basic allocation without pool.

Example

The general pool creation looks like this for

  use lockfree_object_pool::LinearObjectPool;
   
  let pool = LinearObjectPool::<u32>::new(
    ||  Default::default(),
    |v| {*v = 0; });

  // And use the object pool
  let mut item = pool.pull();
  *item = 5;

At the end of the scope item return in object pool.

Multithreading

All implementation support allocation/desallocation from on or more thread. You only need to wrap the pool in a std::sync::Arc :

  use lockfree_object_pool::LinearObjectPool;
  use std::sync::Arc;

  let pool = Arc::new(LinearObjectPool::<u32>::new(
       ||  Default::default(),
       |v| {*v = 0; }));

Performance

Global report.

Allocation

ObjectPoolDuration in Monothreading (us)Duration Multithreading (us)
NoneObjectPool1.21620.63033
MutexObjectPool1.24581.5140
SpinLockObjectPool1.24371.3737
LinearObjectPool0.217640.22418
crate 'sharded-slab'1.50.82790
crate 'object-pool'0.619560.26323

Report monothreading and multithreading.

Desallocation

ObjectPoolDuration in Monothreading (ns)Duration Multithreading (ns)
NoneObjectPool91.36286.530
MutexObjectPool25.486101.40
SpinLockObjectPool22.08950.411
LinearObjectPool7.138434.481
crate 'sharded-slab'9.027311.127
crate 'object-pool'20.03847.768

Report monothreading and multithreading.

Structs

LinearObjectPool

ObjectPool use a lockfree vector to secure multithread access to pull.

LinearReusable

Wrapper over T used by LinearObjectPool.

MutexObjectPool

ObjectPool use a std::sync::Mutex over vector to secure multithread access to pull.

MutexReusable

Wrapper over T used by MutexObjectPool.

NoneObjectPool

Basic allocation without pull. Used to compare default rust allocation with different kind of object pool.

NoneReusable

Wrapper over T used by NoneObjectPool.

SpinLockObjectPool

ObjectPool use a spin lock over vector to secure multithread access to pull.

SpinLockReusable

Wrapper over T used by SpinLockObjectPool.