[concurrency-interest] Relativity of guarantees provided by volatile

Marko Topolnik mtopolnik at inge-mark.hr
Sat Aug 18 17:50:52 EDT 2012

> It seems imperative that, on any physical model of JMM, among
> synchronization actions, if a happens-before b, then there's a causal
> relationship from a to b, and it's necessary that
> a.startTime<b.endTime (on any observer's clock). In that sense, the
> term happens-before is literal after all?

Although admittedly exotic, theoretically the JVM might _predict_ what a future action will write and let that value be read by another thread ahead of time, creating a happens-before that travels back through time without disrupting the JMM's stipulations.

> In OP's example, there are so(r_i, w_j), but there's no hb(r_i, w_j),
> therefore there's no temporal constraints, w_j can occur before r_i.
> If there were something that established hb(r_i, w_j), then the
> example is impossible under JMM.
> Interestingly, JMM also defines r_i and w_j to be in a data race, even
> though they are all volatile.

This a very nice catch. Isn't in fact any read in a data race with all writes by another thread following the write it observed? That would make it impossible to write a program free of data races. In other words this sounds like a loophole in the definition of a data race.

> Could it be true that, if an execution is free of data race, it is
> temporally consistent, i.e. its synchronization order is consistent
> with temporal order.

I think that any synchronization order is temporally consistent, save for perversions like the one I mention above. Whether there are also data races shouldn't matter as they are not included in the synchronization order, anyway.


More information about the Concurrency-interest mailing list