1 `folly/ProducerConsumerQueue.h`
2 -------------------------------
4 The `folly::ProducerConsumerQueue` class is a one-producer
5 one-consumer queue with very low synchronization overhead.
7 The queue must be created with a fixed maximum size (and allocates
8 that many cells of sizeof(T)), and it provides just three simple
9 operations: read, write, and isFull. All of these operations are
10 wait-free. The read and write operations must only be called by the
11 reader and writer thread, respectively, but isFull is accessible to
14 Both read and write may fail if the queue is full, so in many
15 situations it is important to choose the queue size such that the
16 queue filling up for long is unlikely.
21 A toy example that doesn't really do anything useful:
24 folly::ProducerConsumerQueue<folly::fbstring> queue;
26 std::thread reader([&queue] {
29 while (!queue.read(str)) continue;
37 folly::fbstring str = source();
38 while (!queue.write(str)) continue;