Skip to content

Commit 44caa14

Browse files
committed
Lahenda modelcheck/mutex praktikumis
1 parent e15dda4 commit 44caa14

1 file changed

Lines changed: 53 additions & 6 deletions

File tree

src/modelcheck/mutex/modelcheck_mutex.ml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,36 @@ struct
2828
flag = false;
2929
}
3030

31-
31+
let step1 (s: t): t list =
32+
match s.p1 with
33+
| P1 ->
34+
if s.flag then
35+
[s]
36+
else
37+
(* [{p1 = P2; p2 = s.p2; flag = s.flag}] *)
38+
[{s with p1 = P2}]
39+
| P2 -> [{s with p1 = P3; flag = true}]
40+
| P3 -> [{s with p1 = P4}]
41+
| P4 -> [{s with p1 = P5; flag = false}]
42+
| P5 -> []
43+
44+
let step2 (s: t): t list =
45+
match s.p2 with
46+
| P1 ->
47+
if s.flag then
48+
[s]
49+
else
50+
[{s with p2 = P2}]
51+
| P2 -> [{s with p2 = P3; flag = true}]
52+
| P3 -> [{s with p2 = P4}]
53+
| P4 -> [{s with p2 = P5; flag = false}]
54+
| P5 -> []
3255

3356
let step (s: t): t list =
34-
failwith "TODO"
57+
step1 s @ step2 s
3558

3659
let is_error (s: t): bool =
37-
failwith "TODO"
60+
s.p1 = P3 && s.p2 = P3
3861
end
3962

4063
(** Petersoni algoritm (https://en.wikipedia.org/wiki/Peterson%27s_algorithm):
@@ -72,13 +95,37 @@ struct
7295
turn = T1;
7396
}
7497

75-
98+
let step1 (s: t): t list =
99+
match s.p1 with
100+
| P1 -> [{s with p1 = P2; flag1 = true}]
101+
| P2 -> [{s with p1 = P3; turn = T2}]
102+
| P3 ->
103+
if s.flag2 && s.turn = T2 then
104+
[s]
105+
else
106+
[{s with p1 = P4}]
107+
| P4 -> [{s with p1 = P5}]
108+
| P5 -> [{s with p1 = P6; flag1 = false}]
109+
| P6 -> []
110+
111+
let step2 (s: t): t list =
112+
match s.p2 with
113+
| P1 -> [{s with p2 = P2; flag2 = true}]
114+
| P2 -> [{s with p2 = P3; turn = T1}]
115+
| P3 ->
116+
if s.flag1 && s.turn = T1 then
117+
[s]
118+
else
119+
[{s with p2 = P4}]
120+
| P4 -> [{s with p2 = P5}]
121+
| P5 -> [{s with p2 = P6; flag2 = false}]
122+
| P6 -> []
76123

77124
let step (s: t): t list =
78-
failwith "TODO"
125+
step1 s @ step2 s
79126

80127
let is_error (s: t): bool =
81-
failwith "TODO"
128+
s.p1 = P4 && s.p2 = P4
82129
end
83130

84131
(** Dekkeri algoritm (https://en.wikipedia.org/wiki/Dekker%27s_algorithm):

0 commit comments

Comments
 (0)