Use SPSCQueue for single-producer single-consumer communication
masterSPSCQueue is a wait-free and lock-free fixed-size queue designed for C++11. It is optimized for scenarios where exactly one thread performs enqueue operations (the producer) and exactly one thread performs dequeue operations (the consumer).
Warning: Any other usage pattern (e.g., multiple producers or multiple consumers) is invalid and will lead to undefined behavior.
SPSCQueue<int> q(1);
auto t = std::thread([&] {
while (!q.front());
std::cout << *q.front() << std::endl;
q.pop();
});
q.push(1);
t.join();