Hey everyone! I recently published qring, a lightweight, zero-allocation, lock-free ring buffer for Rust designed for low-latency concurrent data handoffs.
I'm sharing it here to get some technical feedback from the community, especially regarding atomic soundness and API design.
Key Architectural Details
-
SPSC Focus (for now): Optimized specifically for Single-Producer Single-Consumer pipelines. Support for MPSC, SPMC, and MPMC topologies is currently in development.
-
Slice Batching (
pop_slice,push_exact): Allows moving chunks of data at once instead of doing single-element loops, reducing per-element atomic synchronization overhead during bulk transfers. -
no_stdReady: Runs on bare-metal and embedded systems without requiring a dynamic memory allocator. -
Cache-Aligned (
#[repr(align(64))]): Producer and consumer state sit on separate cache lines to prevent false sharing across CPU cores. -
Strict Atomics: Built around explicit
Acquire/Releasememory orderings for lock-free safety without unnecessary CPU fences.
Quick Example
Rust
use qring::spsc::SpscQueue;
fn main() {
// Split into producer/consumer handles (capacity: 1024)
let (mut producer, mut consumer) = SpscQueue::<u8, 1024>::split();
// Push batch data efficiently
let data = [1, 2, 3, 4, 5];
let _ = producer.push_exact(&data);
// Pop straight into a slice
let mut read_buf = [0u8; 5];
let popped = consumer.pop_slice(&mut read_buf);
assert_eq!(popped, 5);
assert_eq!(read_buf, [1, 2, 3, 4, 5]);
}
Looking for Feedback
Since lock-free data structures rely heavily on precise memory ordering, I would really appreciate input on:
-
Soundness & Atomics Audit: Extra eyes on the atomic orderings (
Acquire/Release) and memory safety invariants. -
API Ergonomics: Thoughts on the slice batching interface (
pop_slice/push_exact) or suggested additions for zero-copy operations. -
no_stdSetup: Any edge cases or improvements for embedded targets.
Links
If you find qring interesting or useful, feel free to star the repository on GitHub—it really helps with visibility! Looking forward to hearing your thoughts and suggestions.