Nothing Orders Memory

Both atomics start at 0.

std::atomic<int> x{0}, y{0};

// thread A
x.store(1, std::memory_order_relaxed);
y.store(1, std::memory_order_relaxed);

// thread B
int a = y.load(std::memory_order_relaxed);   // reads 1
int b = x.load(std::memory_order_relaxed);   // reads ?

Thread B observes a == 1. Is b == 0 a legal outcome under the C++ memory model?

A

Yes, but only if x and y land on different cache lines; sharing a line would force them to become visible together.

B

Yes: relaxed orders no memory beyond making each individual operation atomic, so B may see A's store to y without seeing its earlier store to x.

C

No: the two stores are program-ordered in A, and atomic operations preserve program order as seen by every thread.

D

No on x86 and yes on ARM, so the answer depends on the target rather than on the standard.