whatisgithub

What is readerwriterqueue?

cameron314/readerwriterqueue — explained in plain English

Analysis updated 2026-06-26

4,553C++Audience · developerComplexity · 3/5LicenseSetup · easy

In one sentence

A C++ header-only library for fast, lock-free data transfer between exactly one producer thread and one consumer thread, with constant-time enqueue and dequeue operations and no external dependencies.

Mindmap

mindmap
  root((readerwriterqueue))
    What it does
      Lock-free queue
      One producer one consumer
      Constant time ops
    Variants
      Standard queue
      Blocking variant
      Fixed capacity circular
    Setup
      Header-only
      CMake FetchContent
      System install
    Platforms
      x86 ARM PowerPC
      BSD License
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Pass audio samples from a capture thread to a processing thread without blocking or audio dropouts

USE CASE 2

Feed sensor data from an input thread to a worker thread in an embedded or real-time system

USE CASE 3

Replace a mutex-protected queue in a two-thread pipeline to reduce latency and CPU overhead

USE CASE 4

Stream network packets from a receive thread to a processing thread without locks

What is it built with?

C++

How does it compare?

cameron314/readerwriterqueueztxz16/fastllmogrecave/ogre
Stars4,5534,5584,561
LanguageC++C++C++
Setup difficultyeasymoderatehard
Complexity3/54/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Drop two header files into your project, requires a C++ build toolchain but no other dependencies.

Simplified BSD License, use freely in personal and commercial projects.

So what is it?

This is a C++ library that solves a specific, narrow problem: passing data quickly between exactly two threads, where one thread produces data and the other consumes it. The author designed the queue from scratch specifically for this two-thread setup. If you need to share data across more than two threads simultaneously, this library is not the right fit, and the README points to a sibling project for that case. The core idea is a lock-free queue, which means threads never have to wait for each other to release a shared lock before reading or writing. Instead, the design uses lower-level techniques that let both threads operate mostly without blocking. The result is very low overhead per item, and both the add and remove operations always complete in constant time, meaning performance does not degrade as the queue grows. The library comes as a pair of header files you drop directly into your project source, no separate compilation or installation required. You create a queue, call enqueue to add items and try_dequeue to remove them. There is also a blocking variant where the consumer thread can wait until something arrives rather than repeatedly checking. A circular buffer version with a fixed capacity is available too, which can block both on adding and removing. For projects using CMake, a standard FetchContent block can pull the library in automatically at build time. Alternatively, you can install the headers into your system directories and include them like any system library. One important limitation noted in the README: the library works correctly on all modern processor families, including x86, ARM, and PowerPC, but is not suitable for the older DEC Alpha architecture due to that chip's unusual memory ordering rules. The license is simplified BSD, which allows free use in personal and commercial projects.

Copy-paste prompts

Prompt 1
I have two C++ threads, one producing sensor readings and one consuming them. Show me how to set up readerwriterqueue so the producer never blocks the consumer.
Prompt 2
How do I add cameron314/readerwriterqueue to my CMake project using FetchContent and what is the minimal code to enqueue and dequeue an item?
Prompt 3
Explain the difference between the regular readerwriterqueue and the blocking variant and when I should use each one.
Prompt 4
I have a real-time audio callback that must never block. Show me how to use readerwriterqueue to safely pass audio buffers to a background processing thread.

Frequently asked questions

What is readerwriterqueue?

A C++ header-only library for fast, lock-free data transfer between exactly one producer thread and one consumer thread, with constant-time enqueue and dequeue operations and no external dependencies.

What language is readerwriterqueue written in?

Mainly C++. The stack also includes C++.

What license does readerwriterqueue use?

Simplified BSD License, use freely in personal and commercial projects.

How hard is readerwriterqueue to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is readerwriterqueue for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.