[concurrency-interest] Volatile happens before question

Vitaly Davidovich vitalyd at gmail.com
Tue Jan 17 18:31:58 EST 2012


No. You lost the transitive relationship of happens-before with your second
statement. Your code can be reordered and executed as follows:

Thread 1 Thread 2 if (!a) // sees false a = true b = 1; bStore =b; print //
prints 1

This actually isn't valid because in original code nothing would print if a
is false - it doesn't enter the if block.  However, compiler can simply
move b=1 before a =true as that's permissible and maybe it'll do that for
some register allocation purposes, as an example.

Sent from my phone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120117/26063ca2/attachment.html>


More information about the Concurrency-interest mailing list