Lock-free Queue Class
Implement a single-producer single-consumer lock-free circular queue using atomics.
Constraints
- Use std::atomic for head and tail.
- Fixed size 8.
- push returns false if full.
- pop returns false if empty.
- No mutex allowed.
1#include <atomic>2 3class LFQ {4private:5 int buf[8];6 std::atomic<int> head, tail;7public:8 LFQ();9 bool push(int x);10 bool pop(int &x);11};