ProMeLa implementation tweaks
This commit is contained in:
parent
4f00be95f5
commit
46c19ef89f
1 changed files with 25 additions and 3 deletions
|
@ -5,15 +5,26 @@
|
||||||
int to_reverse[LENGTH]; // array to reverse
|
int to_reverse[LENGTH]; // array to reverse
|
||||||
int reversed[LENGTH]; // array where the reverse is stored
|
int reversed[LENGTH]; // array where the reverse is stored
|
||||||
|
|
||||||
|
mtype = { END };
|
||||||
|
|
||||||
// ThreadedReverser implementation
|
// ThreadedReverser implementation
|
||||||
proctype ThreadedReverser(int from; int to) {
|
proctype ThreadedReverser(int from; int to; chan out) {
|
||||||
|
printf("proc[%d]: started\n", _pid);
|
||||||
|
|
||||||
int k;
|
int k;
|
||||||
for (k: from .. to) {
|
for (k: from .. to) {
|
||||||
reversed[LENGTH - k - 1] = to_reverse[k];
|
reversed[LENGTH - k - 1] = to_reverse[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("proc[%d]: ended\n", _pid);
|
||||||
|
|
||||||
|
end:
|
||||||
|
out!_pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
chan in = [N] of { mtype };
|
||||||
|
|
||||||
// array initialization
|
// array initialization
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -27,6 +38,10 @@ init {
|
||||||
// ParallelReverser implementation
|
// ParallelReverser implementation
|
||||||
int n;
|
int n;
|
||||||
int s = LENGTH / N;
|
int s = LENGTH / N;
|
||||||
|
|
||||||
|
pid pids[N];
|
||||||
|
|
||||||
|
// fork section
|
||||||
for (n: 0 .. N) {
|
for (n: 0 .. N) {
|
||||||
int from = n * s;
|
int from = n * s;
|
||||||
int to;
|
int to;
|
||||||
|
@ -34,7 +49,14 @@ init {
|
||||||
:: (n == N - 1) -> to = LENGTH;
|
:: (n == N - 1) -> to = LENGTH;
|
||||||
:: else -> to = n * s + s;
|
:: else -> to = n * s + s;
|
||||||
fi
|
fi
|
||||||
run ThreadedReverser(from, to);
|
pids[n] = run ThreadedReverser(from, to, in);
|
||||||
|
}
|
||||||
|
|
||||||
|
// join section
|
||||||
|
for (n: 0 .. N) {
|
||||||
|
in??eval(pids[n]);
|
||||||
|
|
||||||
|
printf("init: joined process %d\n", pids[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue