[concurrency-interest] Relativity of guarantees provided by volatile

Boehm, Hans hans.boehm at hp.com
Tue Aug 21 14:03:06 EDT 2012


> From: Marko Topolnik
> On 20. kol. 2012., at 23:20, Boehm, Hans wrote:
> > Right.  But time ordering is not really observable.  Values returned
> by currentTimeMillis() and the like are observable, but the
> specification is, AFAICT, unclear about the extent to which those
> values have to reflect any kind of real "time ordering".  I suspect
> that, at least on some machines, they use per-processors timers that
> are not perfectly synchronized.
> 
> Let's say that they could in theory be reflecting the exact time. We
> don't have to descend into the gory details of specific CPUs. Imagine a
> CPU specifically built to allow precise wall-clock time observation.

Then I think it depends on how the CPU makes that time available to clients.
If it does it in a way that's equivalent to regularly updating a volatile
variable that can be read by all threads, then timing should work as expected.
I think the current specification for the timing functions is effectively
much weaker, because it's silent on the issues.

I think that if we agree this is a problem, then it could be fixed by
updating the specifications for the timing functions, without touching the
memory model per se.  I'm not sure I understand the implementation
implications of that, so I'm neither advocating it, nor lobbying against it.
The C++ specification is somewhere in the middle, and I remain a bit nervous
about implementability there.

Hans



More information about the Concurrency-interest mailing list