forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bakery_lamport_na_wb.cub
160 lines (128 loc) · 3.48 KB
/
bakery_lamport_na_wb.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
type location = NCS | Choosing | Choosen | Wait | CS | Crash
array PC[proc] : location
array Ticket[proc] : int
array Num[proc] : int
array Num_buffer[proc] : int
array Num_wb[proc] : bool
array Choose[proc] : bool
array Choose_buffer[proc] : bool
array Choose_wb[proc] : bool
var Max : int
array Cpt[proc,proc] : bool
init (x y) { PC[x] = NCS && Num[x] = 0 && Choose[x] = False &&
Max = 1 && Ticket[x] = 0 && Cpt[x,y] = False &&
Choose_wb[x] = False && Num_wb[x] = False }
invariant () { Max < 0 }
invariant () { Max <= 0 }
unsafe (x y) { PC[x] = CS && PC[y] = CS }
transition num_wb (x)
requires { Num_wb[x] = True }
{
Num[x] := Num_buffer[x];
Num_wb[x] := False;
}
transition choose_wb (x)
requires { Choose_wb[x] = True }
{
Choose[x] := Choose_buffer[x];
Choose_wb[x] := False;
}
transition next_ticket ()
{
Ticket[j] := case | _ : Max;
Max := Max + 1;
}
(* transition take_ticket (x) *)
(* requires { PC[x] = NCS && *)
(* forall_other j. Num[j] < Max } *)
(* { *)
(* PC[x] := Choosen; *)
(* Ticket[x] := Max; *)
(* Choose[x] := True; *)
(* } *)
transition take_ticket (x)
requires { PC[x] = NCS && Choose_wb[x] = False }
{
PC[x] := Choosing;
Choose_buffer[x] := True;
Choose_wb[x] := True;
}
transition find_ticket_found (x)
requires { PC[x] = Choosing && Choose_wb[x] = False && forall_other j. Cpt[x,j] = True }
{
Cpt[i,j] := case | i = x : False | _ : Cpt[i,j];
Ticket[x] := Max;
PC[x] := Choosen;
}
transition find_ticket_iter (x j)
requires { PC[x] = Choosing && Choose_wb[x] = False && Cpt[x,j] = False && Num[j] < Max }
{
Cpt[x,j] := True;
}
transition assigned (x)
requires { PC[x] = Choosen && Choose_wb[x] = False && Num_wb[x] = False }
{
Choose_buffer[x] := False;
Choose_wb[x] := True;
PC[x] := Wait;
Num[x] := Ticket[x];
(* Num_wb[x] := True; *)
}
(* transition turn (x) *)
(* requires { PC[x] = Wait && *)
(* forall_other j. *)
(* ( Choose[j] = False && Num[j] = 0 || *)
(* Choose[j] = False && Num[x] < Num[j] || *)
(* Choose[j] = False && *)
(* Num[x] = Num[j] && x < j ) } *)
(* { *)
(* PC[x] := CS; *)
(* } *)
transition wait_exit (x)
requires { PC[x] = Wait && Num_wb[x] = False && Choose_wb[x] = False && forall_other j. Cpt[x,j] = True }
{
Cpt[i,j] := case | i = x : False | _ : Cpt[i,j];
PC[x] := CS;
}
transition wait_iter1 (x j)
requires { PC[x] = Wait && Num_wb[x] = False && Choose_wb[x] = False && Cpt[x,j] = False &&
(* PC[j] <> Choosing && PC[j] <> Choosen && *)
Choose[j] = False && Num[j] = 0 }
{
Cpt[x,j] := True;
}
transition wait_iter2 (x j)
requires { PC[x] = Wait && Num_wb[x] = False && Choose_wb[x] = False && Cpt[x,j] = False &&
(* PC[j] <> Choosing && PC[j] <> Choosen && *)
Choose[j] = False && Num[x] < Num[j] }
{
Cpt[x,j] := True;
}
transition wait_iter3 (x j)
requires { PC[x] = Wait && Num_wb[x] = False && Choose_wb[x] = False && Cpt[x,j] = False &&
(* PC[j] <> Choosing && PC[j] <> Choosen && *)
Choose[j] = False && Num[x] = Num[j] && x < j }
{
Cpt[x,j] := True;
}
transition exit (x)
requires { PC[x] = CS && Num_wb[x] = False }
{
PC[x] := NCS;
Num_buffer[x] := 0;
Num_wb[x] := True;
}
transition fail (x)
{
PC[x] := Crash;
}
transition recover (x)
requires { PC[x] = Crash && Choose_wb[x] = False && Num_wb[x] = False }
{
PC[x] := NCS;
Num_buffer[x] := 0;
Num_wb[x] := True;
Choose_buffer[x] := False;
Choose_wb[x] := True;
Cpt[i,j] := case | i = x : False | _ : Cpt[i,j];
}