readerwriterqueue is a lock-free queue for C++ that serves single-producer, single-consumer use cases with minimal synchronization overhead.
The queue solves the problem of coordinating data transfer between two threads without locks, which can cause contention and unpredictable latency. It achieves this through a wait-free design where enqueue and dequeue operations are always O(1) and compile down to simple loads, stores, and branches on x86 platforms, with no compare-and-swap loops. Memory is allocated upfront in contiguous blocks, and the queue provides both a non-blocking try_enqueue method that never allocates and a dynamic enqueue method for growing capacity as needed.
Developers should choose this queue when building systems where two threads need to exchange data with predictable, minimal latency and no lock contention. It suits real-time applications, high-frequency trading systems, and other performance-critical scenarios. The tool is not suitable for multi-producer or multi-consumer patterns; the README notes that a separate multi-producer, multi-consumer implementation exists for those cases. The queue also offers a circular-buffer variant that supports blocking on both enqueue and dequeue operations, providing flexibility for different synchronization patterns.
The project maintains a focused scope on the single-producer, single-consumer case and has been tested primarily on x86 and x86-64 platforms. The implementation is header-only and requires only a modern C++ compiler, making integration straightforward. The codebase includes both a standard queue and a circular-buffer variant, each with blocking and non-blocking methods, giving users options for their specific threading model.