This repository has been archived on 2023-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
soft-an04/ReversalModel/reversal.pml

67 lines
1.3 KiB
Promela
Raw Normal View History

2023-05-08 12:15:13 +00:00
#define N 10
#define LENGTH 3
#define R 2
int to_reverse[LENGTH]; // array to reverse
int reversed[LENGTH]; // array where the reverse is stored
2023-05-08 12:46:00 +00:00
mtype = { END };
// ThreadedReverser implementation
2023-05-08 12:46:00 +00:00
proctype ThreadedReverser(int from; int to; chan out) {
printf("proc[%d]: started\n", _pid);
int k;
for (k: from .. to) {
reversed[LENGTH - k - 1] = to_reverse[k];
2023-05-08 12:46:00 +00:00
}
printf("proc[%d]: ended\n", _pid);
end:
out!_pid;
}
2023-05-08 12:15:13 +00:00
init {
2023-05-08 12:46:00 +00:00
chan in = [N] of { mtype };
2023-05-08 12:15:13 +00:00
// array initialization
{
int i;
for (i in to_reverse) {
int value;
select(value: 0 .. R);
to_reverse[i] = value;
}
}
// ParallelReverser implementation
int n;
int s = LENGTH / N;
2023-05-08 12:46:00 +00:00
pid pids[N];
// fork section
for (n: 0 .. N) {
int from = n * s;
int to;
if
:: (n == N - 1) -> to = LENGTH;
:: else -> to = n * s + s;
fi
2023-05-08 12:46:00 +00:00
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]);
}
2023-05-08 12:15:13 +00:00
}
// ltl syntax: https://spinroot.com/spin/Man/ltl.html
2023-05-08 12:15:13 +00:00
ltl test {
eventually (false) implies true
// eventually (a > b) implies len(q) == 0
}