Lock-free Queue Class

Hard C++ Concurrency
Solve this problem

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.
Starter codeC++
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};