-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelephone.tla
More file actions
76 lines (65 loc) · 2.22 KB
/
Copy pathtelephone.tla
File metadata and controls
76 lines (65 loc) · 2.22 KB
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
----------------------------- MODULE telephone -----------------------------
EXTENDS Sequences, TLC
=============================================================================
\* Modification History
\* Last modified Sat Mar 16 18:09:26 AEDT 2019 by douglas
\* Created Sat Mar 16 17:55:47 AEDT 2019 by douglas
(*--algorithm telephone
variables
to_send = <<1, 2, 3>>,
received = <<>>,
in_transit = {};
begin
while Len(received) /= 3 do
\* send
if in_send /= <<>> then
in_transit := in_transit \union {Head(to_send)};
to_send := Tail(to_send);
end if;
\* receive
either
with msg \in in_transit do
received := Append(received, msg);
in_transit := in_transit \ {msg};
end with;
or
skip;
end either;
end while;
assert recieved = <<1, 2, 3>>;
end algorithm; *)
\* BEGIN TRANSLATION
VARIABLES to_send, received, in_transit, pc
vars == << to_send, received, in_transit, pc >>
Init == (* Global variables *)
/\ to_send = <<1, 2, 3>>
/\ received = <<>>
/\ in_transit = {}
/\ pc = "Lbl_1"
Lbl_1 == /\ pc = "Lbl_1"
/\ IF Len(received) /= 3
THEN /\ IF in_send /= <<>>
THEN /\ in_transit' = (in_transit \union {Head(to_send)})
/\ to_send' = Tail(to_send)
ELSE /\ TRUE
/\ UNCHANGED << to_send, in_transit >>
/\ \/ /\ pc' = "Lbl_2"
\/ /\ TRUE
/\ pc' = "Lbl_1"
ELSE /\ Assert(recieved = <<1, 2, 3>>,
"Failure of assertion at line 32, column 3.")
/\ pc' = "Done"
/\ UNCHANGED << to_send, in_transit >>
/\ UNCHANGED received
Lbl_2 == /\ pc = "Lbl_2"
/\ \E msg \in in_transit:
/\ received' = Append(received, msg)
/\ in_transit' = in_transit \ {msg}
/\ pc' = "Lbl_1"
/\ UNCHANGED to_send
Next == Lbl_1 \/ Lbl_2
\/ (* Disjunct to prevent deadlock on termination *)
(pc = "Done" /\ UNCHANGED vars)
Spec == Init /\ [][Next]_vars
Termination == <>(pc = "Done")
\* END TRANSLATION