C++14 lock-free queue minimizing latency between push/pop operations
Top 25.5% on sourcepulse
This C++14 library provides highly optimized, lock-free, multiple-producer-multiple-consumer (MPMC) queues based on circular buffers. It targets developers building ultra-low-latency systems, aiming to minimize the time between pushing and popping elements by employing a minimalist design with minimal atomic operations and explicit cache-friendliness.
How It Works
The queues utilize fixed-size circular buffers and std::atomic
operations. Key design principles include minimizing atomic instructions, avoiding false sharing, using a linear buffer array, and avoiding heap allocations post-construction. This minimalist approach, including value semantics (copy/move on push/pop), aims for synergy to maximize CPU performance by reducing cache misses and pipeline stalls. Power-of-2 buffer sizes enable efficient index mapping and cache line contention reduction.
Quick Start & Requirements
atomic_queue/include
to your build system's include paths. Alternatively, use vcpkg install atomic-queue
or conan install atomic-queue
.Highlighted Details
AtomicQueue
(for atomic types) and AtomicQueue2
(for non-atomic types), with Optimist
variants for busy-waiting.std::mutex
, boost::lockfree
, moodycamel::ConcurrentQueue
, and others, claiming superior latency and throughput.Maintenance & Community
Licensing & Compatibility
std::atomic
. Reported compatible with Windows, but CI is Linux-only.Limitations & Caveats
Queue size must be fixed at compile or construction time. The library relies on specific OS behaviors and thread scheduling (e.g., SCHED_FIFO
) for optimal performance, and achieving the lowest latency requires careful system configuration. Debug builds include asserts for the NIL value, which must not be pushed.
2 weeks ago
1 day