zenith@ensmp.fr (Steven Ericsson Zenith) (02/01/91)
Well, this morning on rereading my posting revealed at least two errors.
First, the phrase "non-local (automatic)", should read "non-local
(non-automatic)". Secondly - this'll teach me to crow - the example
given has an incorrect bound in "(i = 3 for LIMIT)" so my claim that the
program works is false. It should read:
void main()
{
int i, ok;
%share [LIMIT] int prime;
%write (prime[2], 1);
%cooperate (i = 3 for LIMIT-3) prime(i);
for(i = 2; i < LIMIT; ++i) {
%get (primes[i], ok);
if (ok) printf("%d\n", i);
}
}
void prime(n)
int n;
{
int i, limit, ok;
double function sqrt();
limit = sqrt((double) me) + 1;
for (i = 2; i < limit; ++i) {
%read (primes[i], ok);
if (ok && (me%i == 0)) %write(prime[n], 0);
}
%write(prime[n], 1);
}
This probably went unnoticed since I didn't explain "replication". The 3
numbers we don't test for primality are 0,1,2 - the last number we test
is (LIMIT-1). The phrase (i = b for n) instances n indexes named "i"
with the values b..(b+n-1).
In fact my bounds checking uncovered a second error propogated from the
original Linda program (the for loop in main has an incorrect condition
bound). This is corrected here also.
*Solution to the exercise:*
The reason the original Linda example deadlocks is corrected by the line
%write (prime[2], 1);
which provides the "prime" processes with something to start with.
Otherwise the program will deadlock, as does the Linda version, in the
"prime" function on the line
%read (primes[i], ok);
Steven
--
Steven Ericsson Zenith * Email: zenith@ensmp.fr * Fax:(1)64.69.47.09
| Francais:(1)64.69.47.08 | Office:(1)64.69.48.52
Center for Research in Computer Science - Centre de Recherche en Informatique
CRI - Ecole Nationale Superieure des Mines de Paris
35 rue Saint-Honore 77305 Fontainebleau France
"All see beauty as beauty only because they see ugliness" LaoTzu