forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bakery_lamport.cub
52 lines (43 loc) · 880 Bytes
/
bakery_lamport.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
type location = NCS | Choose | Wait | CS
array PC[proc] : location
array Ticket[proc] : int
array Num[proc] : int
var Max : int
init (x) { PC[x] = NCS && Num[x] = 0 &&
Max = 1 && Ticket[x] = 0 }
invariant () { Max < 0 }
unsafe (x y) { PC[x] = CS && PC[y] = CS }
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] := Choose;
Ticket[x] := Max;
}
transition wait (x)
requires { PC[x] = Choose }
{
PC[x] := Wait;
Num[x] := Ticket[x];
}
transition turn (x)
requires { PC[x] = Wait &&
forall_other j.
(PC[j] <> Choose && Num[j] = 0 ||
PC[j] <> Choose && Num[x] < Num[j] ||
PC[j] <> Choose &&
Num[x] = Num[j] && x < j) }
{
PC[x] := CS;
}
transition exit (x)
requires { PC[x] = CS }
{
PC[x] := NCS;
Num[x] := 0;
}