Build a Lock-Free SPSC Ring Buffer for a Weakly Ordered CPU
Last updated: November 29, 2026
Quick Overview
Implement a single-producer single-consumer ring buffer that needs no locks, and explain exactly which loads need acquire semantics and which stores need release semantics for it to be correct on Arm's weakly ordered memory model.
Arm
November 29, 20260
0
0 solved
Implement a single-producer single-consumer ring buffer that needs no locks, and explain exactly which loads need acquire semantics and which stores need release semantics for it to be correct on Arm's weakly ordered memory model.
Firmware, driver and runtime engineers at Arm regularly hit bugs that never appear on x86 but surface on AArch64 because Arm allows more reordering. The interviewer checks that you can write the data structure and, more importantly, place memory ordering precisely rather than sprinkling full barriers.
What the Interviewer Expects
- Use free-running head and tail counters with a power-of-two mask
- Give each index a single writer
- Write the payload before publishing the tail with a release store
- Read the tail with an acquire load before reading the payload
- Name the AArch64 instructions: LDAR/STLR or DMB ISH, and when LDAPR helps
- Distinguish full from empty without a lock
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- What concrete bug appears on Arm if the tail store is a plain store?
- Why can each side load its own index with relaxed ordering?
- How would false sharing between head and tail hurt, and how do you fix it?
- How would you extend this to multiple producers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
One producer thread and one consumer thread share a fixed buffer. try_push returns False when full, try_pop returns None when empty. No locks. Must be correct on a weakly ordered CPU, where stores...
High-Level Design
Two counters that only grow: tail (written only by the producer) and head (written only by the consumer). Count is tail - head, so full is count == capacity and empty is head == tail; no slo...