[cpp-threads] C++ memory model
Peter Dimov
pdimov at mmltd.net
Wed Sep 23 01:23:58 BST 2009
Nelson, Clark wrote:
>>> I'd like to just delete the second senetnce:
>>>
>>> "Implementations shall not move an atomic operation out of an
>>> unbounded loop."
>>
>> I'd like to cast my vote in favor of the sentence. It does indeed
>> carry little formal value, but in practice, it can (easily) settle a
>> hypothetical
>> debate between a compiler user and a compiler writer about whether
>> such an
>> optimization is allowed.
>
> Well, maybe; but then the argument will turn to the whether the loop
> in question is really "unbounded", and since the standard doesn't
> define "unbounded loop", the argument will continue -- without
> bounds.
An unbounded loop is one that has no (finite) bound. A loop has a bound N if
it never loops more than N times.
> So, for example, is the compiler required to prove that a loop can't
> ever terminate for it to qualify as unbounded?
No. It has to prove that the loop has a bound in order to move atomic
operations out of it.
> I think it would be helpful to see an example of a program for which
> this sentence might be considered relevant.
while( x );
?
while( !x.compare_exchange_weak( &t, t+1 ) );
?
More information about the cpp-threads
mailing list