A fast single-producer, single-consumer lock-free queue implementation for C++ with wait-free operations.
readerwriterqueue is a C++ library implementing a single-producer, single-consumer lock-free queue designed for high-performance inter-thread communication. It provides wait-free enqueue and dequeue operations with O(1) complexity, avoiding the overhead of mutex locks while maintaining type safety through templates.
C++ developers building high-performance multithreaded applications where one thread produces data and another consumes it, such as real-time systems, game engines, or data processing pipelines.
Developers choose readerwriterqueue for its exceptional performance in the SPSC pattern, simple header-only integration, and guaranteed wait-free operations without compare-and-swap loops. It eliminates lock contention while providing both non-blocking and blocking variants.
A fast single-producer, single-consumer lock-free queue for C++
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides wait-free O(1) enqueue and dequeue operations with minimal memory barriers, optimizing for speed on x86 and avoiding compare-and-swap loops.
Fully templated to work with any C++ type, automatically managing object movement and memory without manual intervention, similar to std::queue.
Offers both non-allocating try_enqueue for fixed capacity and dynamically growing enqueue, plus emplace variants for efficient in-place construction.
Includes BlockingReaderWriterQueue with wait_dequeue methods for easier synchronization without busy-waiting, and a circular buffer with blocking enqueue/dequeue.
Strictly single-producer, single-consumer; cannot handle multiple producers or consumers, restricting use in complex threading scenarios.
Primarily tested and optimized for x86; performance and correctness on other architectures like ARM are not guaranteed, as noted in disclaimers.
Destroying the queue while a thread is waiting in wait_dequeue causes undefined behavior, requiring careful lifetime management to avoid crashes.
Requires modern C++11 compilers; specifically, GCC 4.6 has a bug that prevents correct operation, limiting compatibility with older toolchains.