[cpp-threads] infinite loops

Peter Dimov pdimov at mmltd.net
Mon Jul 31 15:01:18 BST 2006


Doug Lea wrote:
> Herb Sutter wrote:
>> Doug Lea wrote:
>>> Boehm, Hans wrote:
>>>> A way out of this dilemma appears to be to state that
>>>>
>>>> ("infinite loop restriction") Programs that contain infinite loops
>>>> without "acquire+" operations have undefined behavior.
>>> Would it suffice to instead say something (not sure how)
>>> that amounts to the following, to avoid undefinedness?
>>>
>>> A construction of the form
>>>    for (i=0;    ; ++i) something; x = 42;
>>> can be transformed to
>>>    x = 42; for (i=0;    ; ++i) something;
>>> if you can establish some k > 0 such that
>>>    for (i=0; i<k; ++i) something; x = 42;
>>> can be transformed to:
>>>    x = 42; for (i=0; i<k; ++i) something;
>>
>> Do you mean to restrict it to such integer loop variables,
>
> No. Sorry not to be clear. The ints here are just a device for
> illustration. Same idea applies to pointer-chasing loops etc.
> Normally, you'd choose k==1, i.e., that loop executes once (if zero
> times then it is uninteresting). But maybe you can only prove that it
> loops twice, and that in this case the reordering is OK. Letting k
> vary like this was just an attempt to allow the basic optimization Hans 
> has in mind
> to essentially always apply.

In other words, your proposed rule is that if

something; something; something; ...; something; x = 42;

can be transformed to

x = 42; something; something; something; ...; something;

for any finite amount of somethings, then it is allowed even when the actual 
amount of iterations may be infinite.

Right? 




More information about the cpp-threads mailing list