Promela refinement
This commit is contained in:
parent
46c19ef89f
commit
5fcfb5ea8e
2 changed files with 21 additions and 23 deletions
|
@ -1,30 +1,29 @@
|
||||||
#define N 10
|
#define N 2
|
||||||
#define LENGTH 3
|
#define LENGTH 3
|
||||||
#define R 2
|
#define R 2
|
||||||
|
|
||||||
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 };
|
// stores termination of each pid
|
||||||
|
bool done[N]; // initialized to false
|
||||||
|
|
||||||
// ThreadedReverser implementation
|
// ThreadedReverser implementation
|
||||||
proctype ThreadedReverser(int from; int to; chan out) {
|
proctype ThreadedReverser(int from; int to; int n) {
|
||||||
printf("proc[%d]: started\n", _pid);
|
printf("proc[%d]: started\n", _pid);
|
||||||
|
|
||||||
int k;
|
int k;
|
||||||
for (k: from .. to) {
|
for (k: from .. to) {
|
||||||
|
printf("reversed[%d] = to_reverse[%d]\n", LENGTH - k - 1, k);
|
||||||
reversed[LENGTH - k - 1] = to_reverse[k];
|
reversed[LENGTH - k - 1] = to_reverse[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("proc[%d]: ended\n", _pid);
|
printf("proc[%d]: ended\n", n);
|
||||||
|
done[n] = true;
|
||||||
end:
|
|
||||||
out!_pid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
chan in = [N] of { mtype };
|
printf("program start\n");
|
||||||
|
|
||||||
// array initialization
|
// array initialization
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -32,36 +31,35 @@ init {
|
||||||
int value;
|
int value;
|
||||||
select(value: 0 .. R);
|
select(value: 0 .. R);
|
||||||
to_reverse[i] = value;
|
to_reverse[i] = value;
|
||||||
|
printf("to_reverse[%d]: %d\n", i, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParallelReverser implementation
|
// ParallelReverser implementation
|
||||||
int n;
|
int n;
|
||||||
int s = LENGTH / N;
|
int s = LENGTH / N;
|
||||||
|
|
||||||
pid pids[N];
|
|
||||||
|
|
||||||
// fork section
|
// fork section
|
||||||
for (n: 0 .. N) {
|
for (n: 0 .. (N - 1)) {
|
||||||
int from = n * s;
|
int from = n * s;
|
||||||
int to;
|
int to;
|
||||||
if
|
if
|
||||||
:: (n == N - 1) -> to = LENGTH;
|
:: (n == N - 1) -> to = LENGTH - 1;
|
||||||
:: else -> to = n * s + s;
|
:: else -> to = n * s + s - 1;
|
||||||
fi
|
fi
|
||||||
pids[n] = run ThreadedReverser(from, to, in);
|
run ThreadedReverser(from, to, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// join section
|
// join section
|
||||||
for (n: 0 .. N) {
|
for (n: 0 .. (N - 1)) {
|
||||||
in??eval(pids[n]);
|
(done[n] == true);
|
||||||
|
printf("init: joined process %d\n", n);
|
||||||
|
}
|
||||||
|
|
||||||
printf("init: joined process %d\n", pids[n]);
|
printf("program end\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ltl syntax: https://spinroot.com/spin/Man/ltl.html
|
// ltl syntax: https://spinroot.com/spin/Man/ltl.html
|
||||||
ltl test {
|
ltl test {
|
||||||
eventually (false) implies true
|
(done[N - 1] == false) U (reversed[LENGTH - 1] == to_reverse[0])
|
||||||
// eventually (a > b) implies len(q) == 0
|
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ fi
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
spin -a reversal.pml
|
spin -a reversal.pml
|
||||||
gcc-13 -Wno-format-overflow -o pan pan.c
|
gcc-13 -Wno-format-overflow -DPRINTF -o pan pan.c
|
||||||
./pan -a "$1"
|
./pan -a "$1"
|
||||||
|
|
||||||
exitcode="$?"
|
exitcode="$?"
|
||||||
|
|
Reference in a new issue