Skip to content

A header-only library that provides wait-free ring buffer utilities for C++ objects.

Notifications You must be signed in to change notification settings

IYP-Programer-Yeah/WaitFreeRingBufferUtilities

Folders and files

NameName
Last commit message
Last commit date
Oct 9, 2020
Jun 19, 2021
Oct 28, 2020
May 1, 2021
Mar 28, 2020
May 1, 2021
May 22, 2020
May 24, 2020
Apr 1, 2020
Oct 9, 2020
May 24, 2020
May 25, 2020

Repository files navigation

Build Status CodeFactor codecov

This is a header-only library that provides wait-free ring buffer utilities for C++ objects.

  • Non-intrusive: All the nodes are pre-allocated inside the ring buffer.
  • Fixed size: The size of the ring buffer is fixed at compile time, and attempts to push will fail if the ring buffer is full.
  • No need for garbage collection.
  • No need for thread registeration.
  • The underlying data structure is an array.
  • Is wait-free, read further here.
  • Provides MPMC, SPMC, MPSC, and SPSC ring buffers.
  • This is a header only library, and if you're using C++17 it does not rely on any 3rd party libraries, on C++11 you are going to need Boost optional.

Motives

Most of the available libraries do not support C++ objects

Most of the available libraries do not support C++ objects at all, or if they do they don't support them properly. Available libraries are usually writen in C and support pointers only. This usually results in difficulties in memory management and disables RAII. It also requires a thread safe object pool that usually yeilds worse performance than that of a single ring-buffer (Even though this design on part of the C libraries adds overhead, this overhead is not accounted for on the benchmarks).

Most of the available libraries are lock-free

Being lock-free doesn't necessarily gaurantee that threads are not going to wait on each other even though there are no locks. Wait-free does gaurantee this. This gaurantee reduces the overhead of each thread on the other, this is also supported by the benchmarks.

Blog Posts

I have two blog post on this ring buffer design. One explaining the algorithm itself, and the part two providing some benchmark comparisons: