-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAB.pml
executable file
·43 lines (43 loc) · 1.03 KB
/
AB.pml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define MAX 10
mtype = {ack,nak,err,next,accept};
proctype transfer(chan in , out , chin, chout){
byte o,i;
in?next(0);
do
::chin?nak(i)->out!accept(i);chout!ack(0)
::chin?ack(i)->out!accept(i);in?next(o);chout!ack(0)
::chin?err(i)->chout!nak(0)
od
}
proctype application (chan in,out)
{
int i=0 , j=0,last_i =0;
do
:: in?accept(i)->assert(i==last_i);
if
::(last_i!=MAX)->last_i = last_i+1
::(last_i ==MAX)
fi
:: out!next(j)->
if
::(j!=MAX) -> j = j+1
::(j==MAX)
fi
od
}
init
{
chan AtoB = [1] of {mtype,byte};
chan BtoA = [1] of {mtype,byte};
chan Ain = [2] of {mtype,byte};
chan Bin = [2] of {mtype,byte};
chan Aout = [2] of {mtype,byte};
chan Bout = [2] of {mtype,byte};
atomic{
run application(Ain,Aout);
run transfer(Aout,Ain,BtoA,AtoB);
run transfer(Bout,Bin,AtoB,BtoA);
run application(Bin,Bout)
};
AtoB!err(0)
}