| Crates.io | shm-primitives |
| lib.rs | shm-primitives |
| version | 0.6.0 |
| created_at | 2025-12-21 13:23:22.994828+00 |
| updated_at | 2026-01-22 23:11:50.736238+00 |
| description | Lock-free primitives for shared memory IPC: SPSC ring buffers and Treiber stack slab allocators |
| homepage | |
| repository | https://github.com/bearcove/roam |
| max_upload_size | |
| id | 1997954 |
| size | 149,227 |
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.
Each primitive has two variants:
Raw (SpscRingRaw, TreiberSlabRaw): Work with raw pointers, suitable for shared memory where you have *mut pointers from mmap. Caller manages memory lifetime.
Region (SpscRing, TreiberSlab): Convenience wrappers that own their backing memory via a Region. These delegate to the Raw implementations internally.
loom - Enables loom-based concurrency testingAll algorithms are tested under loom to verify correctness across all possible thread interleavings:
cargo test -p shm-primitives --features loom
use shm_primitives::{SpscRing, HeapRegion, PushResult};
// Create a ring buffer with capacity 16
let region = HeapRegion::new_zeroed(SpscRing::<u64>::required_size(16));
let ring = SpscRing::<u64>::init(region.region(), 16);
// Split into producer and consumer
let (mut producer, mut consumer) = ring.split();
// Push some values
assert!(matches!(producer.push(42), PushResult::Ok));
assert!(matches!(producer.push(43), PushResult::Ok));
// Pop them back
assert_eq!(consumer.pop(), Some(42));
assert_eq!(consumer.pop(), Some(43));
assert_eq!(consumer.pop(), None);
MIT OR Apache-2.0