It is known that on x86 for the operations load()
and store()
memory barriers memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel
does not require a processor instructions for the cache and pipeline, and assembler's code always corresponds to std::memory_order_relaxed
, and these restrictions are necessary only for the optimization of the compiler: http://www.stdthread.co.uk/forum/index.php?topic=72.0
And this code Disassembly code confirms this for store()
(MSVS2012 x86_64):
std::atomic<int> a;
a.store(0, std::memory_order_relaxed);
000000013F931A0D mov dword ptr [a],0
a.store(1, std::memory_order_release);
000000013F931A15 mov dword ptr [a],1
But this code doesn't comfirm this for load()
(MSVS2012 x86_64), using lock cmpxchg
:
int val = a.load(std::memory_order_acquire);
000000013F931A1D prefetchw [a]
000000013F931A22 mov eax,dword ptr [a]
000000013F931A26 mov edx,eax
000000013F931A28 lock cmpxchg dword ptr [a],edx
000000013F931A2E jne main+36h (013F931A26h)
std::cout << val << "\n";
some_atomic.load(std::memory_order_acquire) does just drop through to a simple load instruction, and some_atomic.store(std::memory_order_release) drops through to a simple store instruction.
Where am I wrong, and does the semantics of std::memory_order_acquire
requires processor instructions on x86/x86_64 lock cmpxchg
or only a simple load instruction mov
as said Anthony Williams?
ANSWER: It is the same as this bug report: http://connect.microsoft.com/VisualStudio/feedback/details/770885