This repository is dedicated to providing a collection of lock-free queues in C++.
In the realm of concurrent programming, there are numerous ways to implement these queues, and several other repositories exist as well.
The goal is to rework various queue types while focusing on making a handful of them efficient, thoroughly tested, and benchmarked.
The SPBroadcastQueue is a versatile queue that can function as both a Single-Producer, Single-Consumer (SPSC) queue and a Single-Producer, Multiple-Consumer (SPMC) queue, depending on the template arguments provided.
It can handle both simple and more complex data types, ensuring that the producer takes care of creating and destroying objects in the queue. The producer synchronizes with consumers and waits for the slowest one when the queue is full.
To use this queue, consumers need to first subscribe
to it, and then they can start consuming messages.
Importantly, all consumers will see all the messages in the queue.
In addition, special attention has been given to optimizing the queue to avoid performance bottlenecks, such as false sharing and cache issues. This optimization leads to increased throughput, especially when the number of consumers grows.
Throughput benchmark measures throughput between two threads for a queue of 2 * size_t
items.
Latency benchmark measures round trip time between two threads communicating using two queues of 2 * size_t
items.
For the most accurate benchmark results, it is recommended to run the benchmarks in your own local environment.
Queue | Throughput (ops/ms) | Latency RTT (ns) |
---|---|---|
SPBroadcastQueue 1 consumer | 436402 | 270 |
SPBroadcastQueue 4 consumers | 160785 | - |