[cpp-threads] infinite loops

Lawrence Crowl lawrence.crowl at gmail.com
Wed Aug 16 23:10:58 BST 2006


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



More information about the cpp-threads mailing list