Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!apple!olivea!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!axion!uzi-9mm.fulcrum.bt.co.uk!nott-cs!piaggio!anw From: anw@maths.nott.ac.uk (Dr A. N. Walker) Newsgroups: comp.lang.misc Subject: After aliassing -- parallelisation? Message-ID: <1990Nov8.183058.25045@maths.nott.ac.uk> Date: 8 Nov 90 18:30:58 GMT References: <5085@lanl.gov> Reply-To: anw@maths.nott.ac.uk (Dr A. N. Walker) Organization: Maths Dept., Nott'm Univ., UK. Lines: 52 In article <5085@lanl.gov> jlg@lanl.gov (Jim Giles) writes: >By the way, as I've pointed out before, the _LACK_ of aliasing >should be the default - the presence of possible aliasing should >require the assertion. It makes sense to make the most commonly >desired configuration be the default. ^^^^^^^ The key word here is "desired". The programmer may "desire" that the program run like a bat out of hell and that what it does is what it seems to do. These desires sometimes conflict. Anyway, what's worrying me now is the prospect of a replay of this debate in respect of parallelisation. The following C fragment is erroneous: int i = 0; int f() { return i++; } ... { int j = (f(), 2) + (f(), 2); printf ("%d\n", i); } because the two invocations of "f" may be run in parallel, so that the two occurrences of "i++" may interfere with each other. But "f" doesn't know it's going to be invoked in parallel, and the rest of the program doesn't know that "f" is dangerous. In real life, this has rarely mattered so far. If there are two separate invocations of "f" on a serial processor, you will get 2 for "i" no matter how you re-order the expression for "j"; if (as in Fortran) you optimise out one of the calls, you get 1, and the programmer who complains can be pointed to some corner of the language definition. But if the two calls of "f" are handed over to different processors, you will usually get 2, but occasionally 1. Insidious bugs strike again. Of course, we never write code like that. But it is easy to write code like "g() + h()" where "g" and "h" happen (unknown to the writer) both to invoke "f". In languages with semaphores or similar, we can write "f" like sema s = 1; f() { int k; down s; k = i++; up s; return k; } but who is going to go to so much trouble [and why will we think of it in the first place]? What should users of C and Fortran do? Pray? -- Andy Walker, Maths Dept., Nott'm Univ., UK. anw@maths.nott.ac.uk