Implementing a lock-free single-producer single-consumer queue in C++
This medium coding problem tests your ability to design and implement a concurrent data structure using only atomic operations—a core skill for high-frequency trading and systems programming roles. You must build a fixed-capacity, bounded queue that allows one producer thread and one consumer thread to exchange data without locks, while respecting strict memory-ordering constraints.
The challenge combines several technical layers: managing a ring buffer with correct index wrapping, choosing the right memory-ordering semantics for each atomic operation (neither too loose nor overly conservative), handling the full and empty states correctly, and ensuring proper resource cleanup under RAII principles. The test suite validates thread-safe sequencing, boundary conditions, and your understanding of when relaxed vs. acquire-release orderings suffice.
- Ring buffer index arithmetic and wraparound logic
- Memory ordering: relaxed, acquire-release, and happens-before relationships
- Lock-free queue state management (empty, full, partial)
- RAII compliance and destructor safety
- Preventing moves and copies via deleted constructors