I am new to Promela and I'm having some difficulties understanding how to calculate the interleaving possibilities of a model. Which one of the statements is counted in the calculation (how do I know which one to take)? Does process P have 5, as well as Q?
#define N 2
proctype P(){
int counter = 0
do
:: counter<N -> printf("P␣"); counter++
:: else -> break
od
}
proctype Q(){
int counter = 0
do
:: counter<N -> printf("Q␣"); counter++
:: else -> break
od
}
init {
atomic{ run P();
run Q();}
}```
1. Run the model in random and interactive mode. How many interleaving possibilities does
the program have and which?
2. How many possibilities are there for arbitrary values of N?
To calculate the interleaving possibilities of a model in Promela, you need to consider the non-deterministic choices made by the processes during execution. In this case, the processes
PandQrun concurrently, and each process has two choices: either to execute the statement inside the loop (if the counter is less than N) or to break out of the loop.Nset to 2 are :PandQare running concurrently, and they have their own local counters (counter) starting from 0.PandQcan increment their counters inside the loop while the conditioncounter<Nis true.Nin a process, it will break out of the loop.Here are the possible interleavings:
PandQincrement their counters twice before breaking out of the loop.)Pincrements its counter, thenQincrements its counter, and this continues.)The interleaving possibilities are only two because the processes are running concurrently, and they have a deterministic choice to increment their counters until the condition
counter<Nis satisfied.For your second question The number of possibilities for arbitrary values of
Ncan be calculated as follows:PandQcan interleave in any order until their counters reachN.PandQ), each havingNchoices (increment the counter or break out), the total number of interleaving possibilities is2^N * 2^N = 4^N.So, for arbitrary values of
N, there are4^Npossible interleaving execution sequences.