[cpp-threads] C++ memory model

Boehm, Hans hans.boehm at hp.com
Tue Sep 22 23:51:59 BST 2009


> From:  Peter Dimov
> Sent: Tuesday, September 22, 2009 3:40 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] C++ memory model
> 
> Nelson, Clark wrote:
> > At this point it would be helpful if the person who wrote that 
> > sentence would please stand up and explain it. :-)
> 
> I didn't write the sentence, but I think I can explain it. It 
> says that, while a finite sequence of atomic loads from the 
> same location can be collapsed into a single atomic load from 
> that location, an infinite sequence cannot be (similarly for 
> stores of the same value to the same location).
> 
> The sentence is redundant and can be turned into a note if 
> the previous
> sentence:
> 
> "Implementations should make atomic stores visible to atomic 
> loads within a reasonable amount of time."
> 
> is made to use "shall" instead of "should". 
> 
I don't object if those of you more experienced with standardese agree.  I'd be concerned about making this normative without a definition of a "reasonable amount of time", and that could be tricky.  I assumed that was the reasonfor the "should".

I think that to make this precise, we'd probably have to talk about fairness.  And there are probably good reasons not to do that, in that it's not clear we want to disallow non-preemptive schedulers.

With a nonpreemptive scheduler, we have to deal with the fact that

atomic<int> x(0);

Thread 1:
x = 1;

Thread 2:
while (!x);

may not terminate, even if the load of x stays in the loop.

I think that makes precise statements here tricky, and perhaps less useful.

Hans



More information about the cpp-threads mailing list