Logo

Coding preview

Implement Lock-Free SPSC Queue

What this preview is

About this preview

Implement Lock-Free SPSC Queue is a medium quant coding problem on concurrency in Cpp, asked at Quant.

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.

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