[cpp-threads] infinite loops

Boehm, Hans hans.boehm at hp.com
Thu Aug 17 00:08:01 BST 2006


Clearly the transformation is invalid if either count13 or count17 is
volatile or atomic, or if an opaque function call is involved.  But lots
of compiler loop transformations that we do all the time have similar
restrictions.  (If memory mapped I/O were involved, one of the above
better apply.)

In particular, I believe many compilers would perform this
transformation at high optimization levels if the loops iterated over a
fixed size array instead of a linked list.  That encounters all the same
issues you mention.

I actually don't think that this transformation is far removed from what
compilers already perform, or that it would be that hard to do for
sequential C++.  (You'd need to know that count13 and count17 don't
alias any data in the list elements, but I suspect that isn't that hard
to know.)  But it probably doesn't occur in any major benchmark suites,
and I have no idea how important it is in general.

Hans

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Lawrence Crowl
> Sent: Wednesday, August 16, 2006 3:11 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] infinite loops
> 
> On 8/15/06, Boehm, Hans <hans.boehm at hp.com> wrote:
> > Can
> >
> > Thread 1a:
> > for (foo *p = q; p != 0; p = p -> next) if (p -> data == 17)
count17++;
> > for (foo *p = q; p != 0; p = p -> next) if (p -> data == 13)
count13++;
> >
> > be transformed to
> >
> > Thread 1b:
> > for (foo *p = q; p != 0; p = p -> next) {
> >     if (p -> data == 17) count17++;
> >     if (p -> data == 13) count13++;
> > }
> >
> > ?
> ....
> > If the list is in fact acyclic and long, the transformed program is 
> > probably about twice as fast as the original.  And I think the 
> > transformation is legal for sequential programs.
> 
> What if count13 and count17 were volatile?
> What if they were memory-mapped I/O?
> What if they were classes with ++ operations?
> 
> I ask because I am not at all convinced that we should be 
> making any substantive distinction between operations on 
> built-in types and arbitrary function calls.  To do so work 
> against one of the goals of C++.
> 
> --
> Lawrence Crowl
> 
> --
> 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