shm-primitives
Lock-free primitives for shared memory IPC.
This crate provides lock-free data structures designed for use in shared memory contexts where you work with raw pointers to memory-mapped regions.
Primitives
- SpscRing / SpscRingRaw: Single-producer single-consumer ring buffer with wait-free operations
- TreiberSlab / TreiberSlabRaw: Treiber stack-based slab allocator with generation counting for ABA protection
Raw vs Region APIs
Each primitive has two variants:
-
Raw (
SpscRingRaw,TreiberSlabRaw): Work with raw pointers, suitable for shared memory where you have*mutpointers from mmap. Caller manages memory lifetime. -
Region (
SpscRing,TreiberSlab): Convenience wrappers that own their backing memory via aRegion. These delegate to the Raw implementations internally.
Features
loom- Enables loom-based concurrency testing
Loom Testing
All algorithms are tested under loom to verify correctness across all possible thread interleavings:
Example
use ;
// Create a ring buffer with capacity 16
let region = new_zeroed;
let ring = init;
// Split into producer and consumer
let = ring.split;
// Push some values
assert!;
assert!;
// Pop them back
assert_eq!;
assert_eq!;
assert_eq!;
License
MIT OR Apache-2.0