in reply to Re^32: Why is the execution order of subexpressions undefined? (magic ruts)
in thread Why is the execution order of subexpressions undefined?
I am not sure why you think that a defined execution order helps, and I think the following gedankenexperiment could help you understand my point of view:
Let's play a game:
We have six houses and a set of bus lines that we can take between the houses. Our goal is to visit all houses, but we can only take the bus lines to go from one house to the next, and the bus only travels in one direction. We have an unlimited number of clones of ourselves. It is obvious that our clones must start in all houses that have no incoming bus, because otherwise they could never reach that house again by bus.
The only extra rule is, that we are not allowed to visit a house Y if there is at least one house X with a bus connection going from X to Y, and we have not yet visited X.
Now, let's consider the following two towns:
lower town upper town a -> b A -> B b -> c B -> C c -> d d -> e D -> E e -> f E -> F
Please take a minute or two to answer the above questions before continuing.
Now, let's transfer this into Execution Order:
The execution order for the expression a,b,c,d,e,f is well defined and ordered, because for any two elements of the expression, it is exactly clear which one has to happen first. For example, c has to be computed before any of d,e,f can be computed.
The execution order for the expression A,B,C,D,E,F is only partially ordered, and it's not even a half-order. There are two ordered subsets however, and for every subexpression in the sets, we can exactly tell which subexpression has to be evaluated first.
So, we can split up the uppercase expression A,B,C,D,E,F into two unrelated subexpressions A,B,C and D,E,F, and each of the two expressions is unrelated to the other and the two calculation sequences can be executed at the computers leisure. The following execution orders could be valid:
A,D,B,C,E,F D,E,F,A,B,C (AD),(BE),(CF) # with a parallel machine
Note that you don't even need a parallel machine - if one of the expressions is, for example, sleep 1, the other expression can still be evaluated while the first expression is sleeping, without needing a real second CPU.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^34: Why is the execution order of subexpressions undefined? (magic ruts)
by BrowserUk (Patriarch) on Apr 16, 2005 at 18:53 UTC | |
by Corion (Patriarch) on Apr 16, 2005 at 19:02 UTC | |
by BrowserUk (Patriarch) on Apr 16, 2005 at 19:36 UTC | |
by Corion (Patriarch) on Apr 16, 2005 at 19:45 UTC | |
by BrowserUk (Patriarch) on Apr 16, 2005 at 19:52 UTC | |
|