Building a lock-free single-producer single-consumer queue
This easy coding problem tests your understanding of concurrent data structures and thread-safe memory management in C++. It is representative of the kind of infrastructure code that quantitative trading platforms rely on to pass data between specialised threads—for instance, between a market-data processing thread and a business-logic execution thread.
A well-implemented SPSC queue requires careful attention to memory ownership, synchronisation primitives (or lack thereof), and the guarantees that come from having exactly one producer and one consumer. You will need to think about how to signal completion without busy-spinning forever, how to manage dynamic allocation cleanly under RAII, and how to ensure all accesses are atomic or thread-confined.
- Lock-free vs. mutex-based synchronisation
- Memory ordering and atomic variables
- RAII resource lifetime and destructor semantics
- Callback-based consumption patterns
- Signalling and termination conditions in producer-consumer systems