[cpp-threads] Temporal models

Boehm, Hans hans.boehm at hp.com
Fri Mar 24 01:57:30 GMT 2006


I'd like to echo Jeremy's question here.

I think there are several different issues here:

1) For ordinary memory accesses in C++, you really can't tell whether
one is ordered before the other because one depends on the other.  To
detect this, you would need a race, rendering the program undefined.

2) For atomic accesses, in C++ you don't get implicit ordering between
two operations in a thread because one "causes" the other, except for
the "depends on" relation, which is limited to atomic stores depending
on loads.  This relation somewhat violates Jeremy's statement about
defining dependence, except that it talks about dynamic dependence, and
I think only in a case in which that makes sense.

Note that if you say

r1 = unordered_atomic_load(&x);
r2 = unordered_atomic_load(r1);

the load of r1 does not happen-before the load of r2, even though they
"depend" on each other.  If you want that, you need the acquire version
when loading r1.  This is acceptable only because most programmers
should never deal with it.  If you program with locks (or transactions)
and ordinary variables, it never comes up.  (This does prevent you from
taking advantage of some dependence-based ordering constraints enforced
by most hardware.  E.g. it slows down some variants of
double-checked-locking on Itanium and PowerPC.  But as Jeremy pointed
out, that quickly gets tricky due to compiler optimizations.)

3) [I think this is what was meant.] There is an interesting question
that Nick has pointed out before of whether communication through
external actions implies a happens-before relationship.  If thread 1
writes to a file, and thread 2 sees the result, does the write
happen-before the read?  My impression is that Java leaves this
underspecified, as does everything else.  The current C++ proposal
currently has a vague statement about this, but I think this really
needs to be pushed into the library spec.

Hans

 

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Jeremy Manson
> Sent: Thursday, March 23, 2006 3:13 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] Temporal models
> 
> Hi all,
> 
> My name is Jeremy Manson, and I was involved with the Java 
> memory model effort.  I have been sporadically following the 
> conversation, but I am mostly just jumping in here without a 
> lot of context, so forgive me if I get the wrong end of the stick.
> 
> Nick Maclaren wrote:
> > 
> > Note that I am NOT asking for any more precision in when events are 
> > serialised - i.e. the current lack of definition on when dubious 
> > memory actions take place can stay.  What I am saying is that, WHEN 
> > the language provides a construction that states that A 
> causes B, then 
> > A happens before B.  Where this differs from the current 
> approaches is 
> > that it permits the use of causality as a sequencing 
> operator, which I 
> > assert is what almost all users will expect.
> > 
> 
> What do you mean by "a construction that states that A causes 
> B"?  This was one of the toughest things to define in Java, 
> because traditional control and data dependences can be 
> (often trivially) removed by the compiler.  It was completely 
> impractical to use them to guarantee an ordering between 
> memory operations.
> 
> I can talk about that more, if that is something that 
> interests the folks here, but I'm not sure you were referring 
> to that.  You might have been just referring to causation 
> implied by external actions.
> 
> Forgive me if this is well-known to the readers of the list.
> 
> 					Jeremy
> 
> --
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk
> http://www.decadentplace.org.uk/cgi-bin/mailman/listinfo/cpp-threads
> 



More information about the cpp-threads mailing list