[concurrency-interest] Volatile happens before question
zhong.j.yu at gmail.com
Wed Jan 18 07:20:56 EST 2012
On Tue, Jan 17, 2012 at 5:13 PM, Boehm, Hans <hans.boehm at hp.com> wrote:
> Another way to look at this is that compiler reordering that is only observable by programs with data races is generally allowed. The program below clearly has an inherent data race on b. If you make b volatile, the data race, and the problem, go away.
Not by the definitions in the book.
Volatile r/w can form a data race, if there is neither hb(r,w) nor
hb(w,r), which is possible when r is before w in synchronization
P.S. Reading JLS, the wording of "allowed to observe" (17.4.5) is
very misleading; it is defined only in term of happens-before order,
meaning a volatile read can be "allowed to observe" a later volatile
More information about the Concurrency-interest