forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ricart_agrawala.cub
151 lines (127 loc) · 3.51 KB
/
ricart_agrawala.cub
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
type location = L1 | L2 | L3 | L4
(* Empty | Idle | Wait | Req | Use | Ack | Exiting | Ok *)
var Timer : real
array State[proc] : location
array Sender[proc] : proc
array Receiver[proc] : proc
array Clock[proc] : real
array Last[proc] : real
array Is_proc[proc] : bool
const Tick : real
init (z) { State[z] = L1 && Clock[z] = 0.0 && Last[z] = 0.0 && Timer = 1.0 }
(* invariant () { Tick <= 0.0 } *)
unsafe (z1 z2 z3 z4) {
State[z1] = L3 && State[z2] = L3 &&
Sender[z1] = Receiver[z1] && Sender[z2] = Receiver[z2] &&
State[z3] = L4 && State[z4] = L4 &&
Sender[z3] <> Receiver[z3] && Sender[z4] <> Receiver[z4] &&
Sender[z3] = z1 && Sender[z4] = z2 &&
Receiver[z3] = z2 && Receiver[z4] = z1
}
transition t1 (z)
requires { State[z] = L1 && Sender[z] = Receiver[z] && 0.0 < Tick }
{
Timer := Timer + Tick;
State[j] := case
| j = z : L2
| State[j] = L1 && Sender[j] = z : L2
| _ : State[j] ;
Clock[j] := case
| j = z : Timer
| State[j] = L1 && Sender[j] = z : Timer
| _ : Clock[j] ;
Last[j] := case
| j = z : Timer
| _ : Last[j]
}
transition t2 (z other)
requires { State[z] = L2 &&
Sender[z] = Receiver[z] &&
Sender[other] <> Receiver[other] &&
State[other] = L3 && Sender[other] = z && 0.0 < Tick}
{
Timer := Timer + Tick;
State[j] := case
| j = z : L2
| j = other : L4
| _ : State[j] ;
Clock[j] := case
| j = z : Timer
| j = other : Timer
| _ : Clock[j] ;
}
transition t3 (z)
requires { State[z] = L2 && Sender[z] = Receiver[z] &&
forall_other j.
(Sender[j] = Receiver[j] || Sender[j] <> z || State[j] = L4) }
{
State[j] := case
| j = z : L3
| _ : State[j]
}
transition t4 (z)
requires { State[z] = L3 && Sender[z] = Receiver[z] }
{
State[j] := case
| j = z : L4
| Sender[j] <> Receiver[j] && State[j] = L4 &&
Sender[j] = z : L1
| _ : State[j] ;
}
transition t5 (z)
requires { State[z] = L4 && Sender[z] = Receiver[z] && 0.0 < Tick &&
forall_other j.
(Sender[j] = Receiver[j] || Receiver[j] <> z || State[j] <> L2) }
{
Timer := Timer + Tick;
State[j] := case
| j = z : L1
| _ : State[j] ;
Clock[j] := case
| _ : Timer ;
}
transition t6 (z other)
requires { State[z] = L1 && Sender[z] = Receiver[z] &&
State[other] = L2 && Sender[other] <> Receiver[other] &&
Receiver[other] = z && Clock[other] <= Clock[z] && 0.0 < Tick }
{
Timer := Timer + Tick;
State[j] := case
| j = z : L1
| j = other : L3
| _ : State[j] ;
Clock[j] := case
| j = z : Timer
| j = other : Timer
| _ : Clock[j] ;
}
transition t7 (z other)
requires { State[z] = L2 && Sender[z] = Receiver[z] &&
State[other] = L2 && Sender[other] <> Receiver[other] &&
Receiver[other] = z && Clock[other] < Last[z] && 0.0 < Tick }
{
Timer := Timer + Tick;
State[j] := case
| j = z : L2
| j = other : L3
| _ : State[j] ;
Clock[j] := case
| j = z : Timer
| j = other : Timer
| _ : Clock[j] ;
}
transition t8 (z other)
requires { State[z] = L2 && Sender[z] = Receiver[z] &&
State[other] = L2 && Sender[other] <> Receiver[other] &&
Receiver[other] = z && Clock[other] = Last[z] && Sender[other] < z && 0.0 < Tick }
{
Timer := Timer + Tick;
State[j] := case
| j = z : L2
| j = other : L3
| _ : State[j] ;
Clock[j] := case
| j = z : Timer
| j = other : Timer
| _ : Clock[j] ;
}