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

65 lines
1.4 KiB
Promela
Raw Normal View History

2023-05-08 13:22:41 +00:00
#define N 2
2023-05-08 12:15:13 +00:00
#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 13:22:41 +00:00
// stores termination of each pid
bool done[N]; // initialized to false
2023-05-08 12:46:00 +00:00
// ThreadedReverser implementation
2023-05-08 13:22:41 +00:00
proctype ThreadedReverser(int from; int to; int n) {
2023-05-08 12:46:00 +00:00
printf("proc[%d]: started\n", _pid);
int k;
for (k: from .. to) {
2023-05-08 13:22:41 +00:00
printf("reversed[%d] = to_reverse[%d]\n", LENGTH - k - 1, k);
reversed[LENGTH - k - 1] = to_reverse[k];
2023-05-08 12:46:00 +00:00
}
2023-05-08 13:22:41 +00:00
printf("proc[%d]: ended\n", n);
done[n] = true;
}
2023-05-08 12:15:13 +00:00
init {
2023-05-08 13:22:41 +00:00
printf("program start\n");
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;
2023-05-08 13:22:41 +00:00
printf("to_reverse[%d]: %d\n", i, value);
2023-05-08 12:15:13 +00:00
}
}
// ParallelReverser implementation
int n;
int s = LENGTH / N;
2023-05-08 12:46:00 +00:00
// fork section
2023-05-08 13:22:41 +00:00
for (n: 0 .. (N - 1)) {
int from = n * s;
int to;
if
2023-05-08 13:22:41 +00:00
:: (n == N - 1) -> to = LENGTH - 1;
:: else -> to = n * s + s - 1;
fi
2023-05-08 13:22:41 +00:00
run ThreadedReverser(from, to, n);
2023-05-08 12:46:00 +00:00
}
// join section
2023-05-08 13:22:41 +00:00
for (n: 0 .. (N - 1)) {
(done[n] == true);
printf("init: joined process %d\n", n);
}
2023-05-08 12:46:00 +00:00
2023-05-08 13:22:41 +00:00
printf("program end\n");
2023-05-08 12:15:13 +00:00
}
// ltl syntax: https://spinroot.com/spin/Man/ltl.html
2023-05-08 13:22:41 +00:00
ltl test {
(done[N - 1] == false) U (reversed[LENGTH - 1] == to_reverse[0])
2023-05-08 12:15:13 +00:00
}