I have the following code:
#include <cstdint>
#include <atomic>
void myAtomicStore(std::atomic<int32_t>& i, const int32_t v) {
i.store(v, std::memory_order_release);
}
int myAtomicLoad(std::atomic<int32_t>& i, const int32_t v) {
return i.load(std::memory_order_acquire);
}
And (according to this) GCC 8.1 translated it (for x86_64) into:
myAtomicStore(std::atomic<int>&, int):
mov DWORD PTR [rdi], esi
ret
myAtomicLoad(std::atomic<int>&, int):
mov eax, DWORD PTR [rdi]
ret
I wonder how the mov
's instructions can make all the writes to memory prior to myAtomicStore()
become visible to another thread when it calls myAtomicLoad()
on the same variable (or memory location) -- guaranteed by C++ standard.
I skimmed Intel's manual; and I don't see anything obvious.
Thanks!