Rewrite this README file for a broadcast queue data structure: A single-producer,…
- User
Rewrite this README file for a broadcast queue data structure:
A single-producer, multiple-consumer broadcast queue for POD datatypes for C++11
This repository contains an implementation of a fixed-size seqlock broadcast queue based on the paper Can Seqlocks Get Along With Programming Language Memory Models? by Hans Bohem.
Semantics
This is a fixed-size circular queue that consists of two parts: a sender and one or more receivers. Its API is inspired by Golang's channels. The sender broadcasts its values to all receivers that have subscribed to it. When a receiver subscribes to a sender, it starts receiving data from the point it subscribed.
If the sender writes over a part of the queue before a receiver dequeues it, the receiver is considered to be lagging behind. In this case, the next time the receiver tries to dequeue a value, it will receive a
broadcast_queue::Error::Laggederror. The receiver's position in the queue is then updated to the tip of the queue, which is the point where the sender will write the next value. Once the sender writes the next value, the receiver will receive it as if it had just resubscribed.If the sender dies, the channel is considered closed, and if a receiver tries to dequeue data from it, it will receive a
broadcast_queue::Error::Closederror.Reasons to use
The main setting for using this kind of implementation is real-time applications where slow receivers are not tolerated. Here, the
senderdoesn't care aboutreceivers not being able to catch up, and writes into the queue without giving them any regard. For examaple, my personal use case was writing a server that serves real-time audio data for many clients. I can't have the server waiting on clients, and I can't create a queue for each client since the memory usage would be suboptimal. So instead, all clients share the same queue, and any lagging client will simply drop elements after being notified.Example
C++ - Assistant
This repository provides a C++11 implementation of a single-producer, multiple-consumer broadcast queue that is ideal for handling POD datatypes. It is based on the fixed-size seqlock broadcast queue introduced by Hans Bohem in his paper "Can Seqlocks Get Along With Programming Language Memory Models?".