Master the fundamental concepts of lock-free & wait-free programming through this focused micro-challenge.
When only one thread produces and one consumes, a ring buffer with atomic head and tail needs no CAS on both sides. Linux kfifo, Disruptor, and game engine job queues use this pattern for millions of events per second.
Producer writes slot at tail % cap, then publishes tail. Consumer reads at head % cap, then publishes head. Power-of-two capacity makes modulo a bitmask.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will implement an SPSC ring buffer with release/acquire ordering. This exercise asks you to pass a stress test with one producer and one consumer thread.
Implement SPSC lock-free queue.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github