3 ms·
tl;dr explanation of the bug: memory_order_acquire guarantees that things won't be moved from after it to before it, and memory_order_release guarantees that th
by josephcsible 4y ago
tl;dr explanation of the bug: memory_order_acquire guarantees that things won't be moved from after it to before it, and memory_order_release guarantees that things won't be moved from before it to after it. The buggy code was doing atomicBase.store(nb, memory_order_release) followed by atomicEnd.load(memory_order_acquire), and relied on the order of those not being swapped, which is not guaranteed.
Since x86_64 has a strong memory model, that code just got compiled into regular MOV instructions there. The Intel software developer's manual says "The Intel-64 memory-ordering model allows a load to be reordered with an earlier store to a different location", and that's exactly what triggers the bug there.
On AArch64, that code got compiled into STLR and LDAR instructions, which can't be reordered in that way (see https://stackoverflow.com/q/67397460/7509065 https://stackoverflow.com/q/67397460/7509065 and https://stackoverflow.com/q/65466840/7509065 https://stackoverflow.com/q/65466840/7509065), so the bug didn't show up there.