Leigh Johnston
2010-01-07 23:57:43 UTC
I am confused, the Wikipedia article
http://en.wikipedia.org/wiki/Double-checked_locking claims that VC++
volatile keyword includes a memory barrier however if I compile the
following program:
volatile int n1;
volatile int n2;
int main()
{
++n1;
++n2;
}
I get the following output:
_main PROC ; COMDAT
; 19 : ++n1;
00000 b8 01 00 00 00 mov eax, 1
00005 01 05 00 00 00
00 add DWORD PTR ?n1@@3HC, eax ; n1
; 20 : ++n2;
0000b 01 05 00 00 00
00 add DWORD PTR ?n2@@3HC, eax ; n2
; 21 : }
00011 33 c0 xor eax, eax
00013 c3 ret 0
_main ENDP
I cannot see any memory barrier instructions here unless I am being stupid
so my question is does VC++ volatile keyword provide a memory barrier or
not? I am using VS2008.
/Leigh
http://en.wikipedia.org/wiki/Double-checked_locking claims that VC++
volatile keyword includes a memory barrier however if I compile the
following program:
volatile int n1;
volatile int n2;
int main()
{
++n1;
++n2;
}
I get the following output:
_main PROC ; COMDAT
; 19 : ++n1;
00000 b8 01 00 00 00 mov eax, 1
00005 01 05 00 00 00
00 add DWORD PTR ?n1@@3HC, eax ; n1
; 20 : ++n2;
0000b 01 05 00 00 00
00 add DWORD PTR ?n2@@3HC, eax ; n2
; 21 : }
00011 33 c0 xor eax, eax
00013 c3 ret 0
_main ENDP
I cannot see any memory barrier instructions here unless I am being stupid
so my question is does VC++ volatile keyword provide a memory barrier or
not? I am using VS2008.
/Leigh