forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
szymanski_boleslaw_bool_na.cub
268 lines (217 loc) · 6.03 KB
/
szymanski_boleslaw_bool_na.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
(*
From: B. K. Szymanski. A Simple Solution to Lamport's Concurrent Programming
Problem with Linear Wait. In Proceedings of the International Conference
on Supercomputing Systems (ICS), 1988.
======================== NON ATOMIC VERSION =========================
specific boolean intent, door_in, door_out = false;
local integer j in O..n-1;
P10: intent[i]:=true;
P11: while (j<n) if (intent[j] & door_in[j]) then j=0 else j++;
P20: door_in[i]:=true;
P21: if exists j: intent[j] & !door_in[j] then begin intent[i]:=false;
P22: wait until exists j: door_out[j];
intent[i]:=true; end;
P30: door_out[i] := true;
E0 : wait until forall j>i: !door_in[j] | door_out[j];
P31: wait until forall j<i: !door_in[j];
CS : Critical Section
E1: intent[i]=false; door_in[i]=false; door_out[i]=false;
*)
type location = P10 | P11 | P20 | P21 | P22 | P30 | P31 | CS | E0 | E1
type flag = F0 | F1 | F2 | F3 | F4
array PC[proc] : location
array Intent[proc] : bool
array Door_in[proc] : bool
array Door_out[proc] : bool
array Cpt[proc, proc] : bool
init (x y) { PC[x] = P10 &&
Intent[x] = False && Door_in[x] = False && Door_out[x] = False &&
Cpt[x,y] = False }
unsafe (z1 z2) { PC[z1] = CS && PC[z2] = CS }
transition p10 (i)
requires { PC[i] = P10 }
{
Intent[i] := True;
PC[i] := P11;
}
transition p11 (i)
requires { PC[i] = P11 &&
forall_other j. (Intent[j] = False || Door_in[j] = False) }
{
PC[i] := P20;
}
(* transition p11_while_then (i j) *)
(* requires { PC[i] = P11 && *)
(* Cpt[i,j] = False && (\* forall_other k. (j < k || Cpt[i,k] = True) && *\) *)
(* Intent[j] = True && Door_in[j] = True } *)
(* { *)
(* (\* Reset counter *\) *)
(* Cpt[x,y] := case | x = i : False | _ : Cpt[x,y]; *)
(* } *)
(* transition p11_while_incr1 (i j) *)
(* requires { PC[i] = P11 && *)
(* Cpt[i,j] = False && (\* forall_other k. (j < k || Cpt[i,k] = True) && *\) *)
(* Intent[j] = False } *)
(* { *)
(* Cpt[i,j] := True; (\* j++ *\) *)
(* } *)
(* transition p11_while_incr2 (i j) *)
(* requires { PC[i] = P11 && *)
(* Cpt[i,j] = False && (\* forall_other k. (j < k || Cpt[i,k] = True) && *\) *)
(* Door_in[j] = False } *)
(* { *)
(* Cpt[i,j] := True; (\* j++ *\) *)
(* } *)
(* transition p11_while_exit (i) *)
(* requires { PC[i] = P11 && forall_other j. Cpt[i,j] = True } *)
(* { *)
(* PC[i] := P20; *)
(* (\* Reset counter *\) *)
(* Cpt[x,y] := case | x = i : False | _ : Cpt[x,y]; *)
(* } *)
transition p20 (i)
requires { PC[i] = P20 }
{
Door_in[i] := True;
PC[i] := P21;
}
(* transition p21_then (i j) *)
(* requires { PC[i] = P21 && Intent[j] = True && Door_in[j] = False } *)
(* { *)
(* Intent[i] := False; *)
(* PC[i] := P22; *)
(* } *)
(* transition p21_else (i) *)
(* requires { PC[i] = P21 && forall_other j. (Intent[j] = False || Door_in[j] = True) } *)
(* { *)
(* PC[i] := P30; *)
(* } *)
transition p21_abort_while (i j)
requires { PC[i] = P21 && Cpt[i,j] = False &&
Intent[j] = True && Door_in[j] = False }
{
Intent[i] := False;
PC[i] := P22;
(* Reset counter *)
Cpt[x,y] := case | x = i : False | _ : Cpt[x,y];
}
transition p21_incr1 (i j)
requires { PC[i] = P21 && Cpt[i,j] = False &&
Intent[j] = False }
{
Cpt[i,j] := True;
}
transition p21_incr2 (i j)
requires { PC[i] = P21 && Cpt[i,j] = False &&
Door_in[j] = True }
{
Cpt[i,j] := True;
}
transition p21_exit_while (i)
requires { PC[i] = P21 && forall_other j. Cpt[i,j] = True }
{
(* Reset counter *)
Cpt[x,y] := case | x = i : False | _ : Cpt[x,y];
PC[i] := P30;
}
(* transition p22 (i j) *)
(* requires { PC[i] = P22 && Door_out[j] = True } *)
(* { *)
(* Intent[i] := True; *)
(* Door_out[i] := True; *)
(* PC[i] := E0; *)
(* } *)
transition p22_abort_while (i j)
requires { PC[i] = P22 && Cpt[i,j] = False &&
Door_out[j] = True }
{
Intent[i] := True;
Door_out[i] := True;
PC[i] := E0;
(* Reset counter *)
Cpt[x,y] := case | x = i : False | _ : Cpt[x,y];
}
transition p22_incr (i j)
requires { PC[i] = P22 && Cpt[i,j] = False &&
Door_out[j] = False }
{
Cpt[i,j] := True;
}
transition p22_restart_while (i)
requires { PC[i] = P22 && forall_other j. Cpt[i,j] = True }
{
(* Reset counter *)
Cpt[x,y] := case | x = i : False | _ : Cpt[x,y];
}
transition p30 (i)
requires { PC[i] = P30 }
{
Door_out[i] := True;
PC[i] := E0;
}
(* transition e0 (i) *)
(* requires { PC[i] = E0 && *)
(* forall_other j. (j < i || Door_in[j] = False || Door_out[j] = True) } *)
(* { *)
(* PC[i] := P31; *)
(* } *)
transition e0_incr1 (i j)
requires { PC[i] = E0 && Cpt[i,j] = False &&
Door_in[j] = False }
{
Cpt[i,j] := True;
}
transition e0_incr2 (i j)
requires { PC[i] = E0 && i < j && Cpt[i,j] = False &&
Door_out[j] = True }
{
Cpt[i,j] := True;
}
(* transition e0_incr3 (i j) *)
(* requires { PC[i] = E0 && j < i && Cpt[i,j] = False && *)
(* Door_in[j] = False } *)
(* { *)
(* Cpt[i,j] := True; *)
(* } *)
transition e0_exit (i)
requires { PC[i] = E0 &&
forall_other j. (Cpt[i,j] = True) }
{
PC[i] := CS;
(* not reseting counter *)
(* Reset counter *)
Cpt[x,y] := case | x = i : False | _ : Cpt[x,y];
}
(* transition p31 (i) *)
(* requires { PC[i] = P31 && *)
(* forall_other j. (i < j || Door_in[j] = False) } *)
(* { *)
(* PC[i] := CS; *)
(* } *)
(* transition p31_incr (i j) *)
(* requires { PC[i] = P31 && j < i && Cpt[i,j] = False && *)
(* Door_in[j] = False } *)
(* { *)
(* Cpt[i,j] := True; *)
(* } *)
(* transition p31_exit (i j) *)
(* requires { PC[i] = P31 && *)
(* forall_other j. (i < j || Cpt[i,j] = True) } *)
(* { *)
(* PC[i] := CS; *)
(* (\* Reset counter *\) *)
(* Cpt[x,y] := case | x = i : False | _ : Cpt[x,y]; *)
(* } *)
transition cs_exit (i)
requires { PC[i] = CS }
{
PC[i] := E1;
}
transition e1 (i)
requires { PC[i] = E1 }
{
Intent[i] := False;
Door_in[i] := False;
Door_out[i] := False;
PC[i] := P10;
}