G
Graeme Prentice
According to this web page
http://www.jaggersoft.com/csharp_standard/17.4.3.htm
making data volatile results in ordered reads and writes. Does this
mean that the following (pseudo) code should work (assuming flag1 and
flag2 are volatile)
// thread 1
flag1 = true;
if ( !flag2 )
// perform an operation that needs to be serialised
else
flag1 = false; // try again
// thread 2
flag2 = true;
if ( !flag1 )
// perform an operation that needs to be serialised
else
flag2 = false; // try again
I'm not suggesting to use this code, I just want to know what volatile
does.
If this code works, are special instructions used to ensure that
re-ordering of the reads and writes doesn't occur? What would these
instructions be on X86? Is cache coherency guaranteed on all Windows/C#
platforms?
Graeme
http://www.jaggersoft.com/csharp_standard/17.4.3.htm
making data volatile results in ordered reads and writes. Does this
mean that the following (pseudo) code should work (assuming flag1 and
flag2 are volatile)
// thread 1
flag1 = true;
if ( !flag2 )
// perform an operation that needs to be serialised
else
flag1 = false; // try again
// thread 2
flag2 = true;
if ( !flag1 )
// perform an operation that needs to be serialised
else
flag2 = false; // try again
I'm not suggesting to use this code, I just want to know what volatile
does.
If this code works, are special instructions used to ensure that
re-ordering of the reads and writes doesn't occur? What would these
instructions be on X86? Is cache coherency guaranteed on all Windows/C#
platforms?
Graeme