[concurrency-interest] On A Formal Definition of 'Data-Race'
thurston at nomagicsoftware.com
Tue Apr 16 17:49:18 EDT 2013
I'm wondering if the stopped-flag code were to run on a modern CPU (i.e. with
cache coherency), would there be any practical difference between declaring:
boolean stopped = false
volatile boolean stopped = false
/Note: I'm not advocating the non-volatile, 'broken' version; of course you
should write to the JMM, that's its purpose. I really feel for engineers who
have to write for multiple CPUs/MMs; I don't know how they manage./
But given cache coherency, let's say you were to run the code a gazillion
times and could count the # of loops after setting this.stopped = true.
Should one expect some (even if negligible) difference between the two
versions? I suppose it would depend on a lot of things (is #stopped cached,
false-sharing effects, etc), but due to cc, the run thread, even in the
non-volatile version, should eventually see this.stopped == true -- hmm
unless the JIT were to do the kind of code 'optimization' that Greg showed
(hoisting this.stopped out of the loop), which I guess is allowed.
View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/On-A-Formal-Definition-of-Data-Race-tp9408p9454.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
More information about the Concurrency-interest