Repolode
max0x7ba

max0x7ba/atomic_queue

Header-only C++14 lock-free ring-buffer queues for passing messages between threads with minimal push-to-pop latency.

Stars
1,899
Forks
221
Open issues
1
Last commit
7 days ago

What is it?

atomic_queue is a set of header-only C++14 multiple-producer, multiple-consumer queues built on fixed-capacity ring buffers and std::atomic. Its stated goal is to minimise the time between one thread pushing an element and another thread popping it, so it is aimed at latency-sensitive code such as trading systems and logging hot paths.

The queues use a fixed capacity set at compile time or construction, so no heap allocation happens after construction. Variants exist for atomic element types and for non-atomic types such as std::unique_ptr, with array-backed and heap-backed buffers. Position-independent array-based variants can be placed in shared memory for inter-process use. Both spin-waiting push/pop and non-blocking try_push/try_pop forms are provided, along with an SPSC mode that avoids read-modify-write atomics.

The project is tested in CI on Linux x86_64 and ARM, plus cross-architecture runs under QEMU for RISC-V, PowerPC, s390x and LoongArch, and on Windows x86_64 and macOS ARM via CMake. It can be consumed through CMake, vcpkg or Conan.

Key features

  • 01Header-only C++14 library with no build step required to use it.
  • 02Fixed-capacity ring buffers with no heap allocation after construction.
  • 03Variants for atomic and non-atomic element types, including move-only types like std::unique_ptr.
  • 04Position-independent array-based queues that can live in shared memory.
  • 05Optional totally ordered FIFO mode for push and pop.
  • 06Non-blocking try_push/try_pop and spin-waiting push/pop forms.

Use cases

  • Passing market data or orders between threads in latency-sensitive trading software.
  • Offloading log records from a hot path to a background formatting and I/O thread.
  • Passing small messages between processes through a shared-memory segment.
  • Distributing tasks from producers to a pool of worker threads with bounded capacity.

Things to know

  • The queue capacity is fixed at compile time or construction time, so it cannot grow.
  • There are no OS-blocking push or pop functions, so waiting threads spin and consume CPU.
  • It was developed and benchmarked mainly on Linux x86_64, so other platforms are less proven.

Topics

FAQ

What is atomic_queue?
Header-only C++14 lock-free ring-buffer queues for passing messages between threads with minimal push-to-pop latency. atomic_queue is a set of header-only C++14 multiple-producer, multiple-consumer queues built on fixed-capacity ring buffers and std::atomic. Its stated goal is to minimise the time between one thread pushing an element and another thread popping it, so it is aimed at latency-sensitive code such as trading systems and logging hot paths.
Is atomic_queue free to use? What license does it have?
atomic_queue is open source under the MIT license. Check the license terms before using it in commercial products.
Is atomic_queue still maintained?
Actively maintained. The last commit to atomic_queue was on Oct 16, 2026.
What can I use atomic_queue for?
Passing market data or orders between threads in latency-sensitive trading software. Offloading log records from a hot path to a background formatting and I/O thread. Passing small messages between processes through a shared-memory segment. Distributing tasks from producers to a pool of worker threads with bounded capacity.
Where can I get atomic_queue?
The source code and installation instructions are on GitHub: https://github.com/max0x7ba/atomic_queue

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects