explaingit

cameron314/concurrentqueue

12,261C++Audience · developerComplexity · 3/5Setup · easy

TLDR

A single-header C++ library for passing data between multiple threads without locks, offering high-performance lock-free queuing for multi-threaded applications.

Mindmap

mindmap
  root((concurrentqueue))
    What it solves
      Thread-safe queuing
      No locks needed
      Any data type
    How to use
      Single header file
      Bulk enqueue
      Bulk dequeue
      Blocking variant
    Performance
      Cache-friendly blocks
      Per-producer sub-queues
      Faster than mutex queues
    Trade-offs
      Order not guaranteed
      Not for NUMA hardware
      C++11 required
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

Things people build with this

USE CASE 1

Replace a mutex-protected queue in a multi-threaded C++ app with a lock-free queue to reduce contention and improve throughput

USE CASE 2

Implement a fast producer-consumer pipeline in a game engine or real-time system where latency and throughput matter

USE CASE 3

Use bulk enqueue and dequeue operations to batch-process work items across multiple threads more efficiently than one-at-a-time

Tech stack

C++C++11

Getting it running

Difficulty · easy Time to first run · 30min

Requires a C++11-capable compiler, drop the single header file into your project and include it, no build system changes needed.

In plain English

This is a C++ library that solves a specific problem: passing data between multiple threads safely and quickly, without using traditional locks. A "queue" in programming is a data structure where items are added at one end and removed from the other, like a line at a store. When multiple threads (independent execution paths in a program) all need to read from and write to the same queue at the same time, you normally need a lock to prevent them from colliding. This library avoids that lock entirely, which is why it is described as "lock-free." The entire library is a single header file, meaning you just drop one file into your project and you are done. It handles memory management for you, works with any data type, and places no artificial limits on how many items can be in the queue. There is also a blocking variant included for cases where a consumer thread should wait (rather than just return "nothing found") when the queue is empty. Performance is the primary reason this library exists. The author found that other lock-free queues for C++ either imposed restrictions on the types they could hold or were not actually lock-free. This one supports bulk enqueue and dequeue operations, which are significantly faster than adding or removing items one at a time, especially when many threads are contending for the queue simultaneously. There are meaningful trade-offs to know about. The queue is not linearizable, meaning that if two producers add items at the same time, the order those items come out is not guaranteed across producers. It is also not suitable for NUMA architectures (certain multi-processor hardware layouts) and requires some care with memory ordering in advanced usage patterns. The README includes sample code and links to detailed design documentation for developers who need to understand exactly how it behaves. Internally, items are stored in contiguous blocks of memory rather than linked lists, which improves cache performance. Each producer gets its own sub-queue, and consumers cycle through all sub-queues to find an item to process. The library requires a C++11-capable compiler to build.

Copy-paste prompts

Prompt 1
Show me how to use cameron314/concurrentqueue to pass work items from 4 producer threads to 2 consumer threads in a C++ server, with a code example
Prompt 2
How do I add concurrentqueue to my C++ project and safely enqueue and dequeue items from multiple threads simultaneously?
Prompt 3
What are the trade-offs of concurrentqueue compared to a mutex-protected std::queue? When should I NOT use it?
Prompt 4
Show me how to use the blocking variant of concurrentqueue so consumer threads wait for items instead of spinning in a loop
Open on GitHub → Explain another repo

← cameron314 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.