![]() |
Fleet
0.0.9
Inference in the LOT
|
A concurrent queue class that allows multiple threads to push and consume. Note that this has a fixed, finite size (n) and when its full, we'll block. This prevents us from eating up too much memory. More...
#include <vector>
#include <mutex>
#include <condition_variable>
#include <queue>
#include <optional>
#include "OrderedLock.h"
Go to the source code of this file.
Classes | |
class | ConcurrentQueue< T > |
class | ConcurrentQueueRing< T > |
A concurrent queue class that allows multiple threads to push and consume. Note that this has a fixed, finite size (n) and when its full, we'll block. This prevents us from eating up too much memory.
It turns out that ConcurrentQueue is very slow with many threads. A ConcurrentQueueRing stores a separate ConcurrentQueue for each thread, and then loops through them. Each thread is therefore pushing onto a different ConcurrentQueue (NOTE: These must be ConcurrentQueues instead of e.g. std::queues, since the pusher and the popper are different threads, so they ened all of their locking). ConcurrentQueueRing prevents most of the locking/synchronization slowness, with only a little bit of wasted time for the yielding thread.
This provides no guarantees on the order of pops, which may vary erratically based on occupancy of the underlying queues.
NOTE: A ConcurrentQueueRing is meant to be read by a single thread