-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaceCondition.tla
65 lines (49 loc) · 1.64 KB
/
RaceCondition.tla
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
--------------------------- MODULE RaceCondition ---------------------------
EXTENDS Naturals
CONSTANT N
(*
--algorithm RaceCondition
variables total = 0;
process Proc \in 1..N
variable x
begin
read: x := total;
inc: x := x + 1;
save: total := x;
end process;
end algorithm;
*)
\* BEGIN TRANSLATION
CONSTANT defaultInitValue
VARIABLES total, pc, x
vars == << total, pc, x >>
ProcSet == (1..N)
Init == (* Global variables *)
/\ total = 0
(* Process Proc *)
/\ x = [self \in 1..N |-> defaultInitValue]
/\ pc = [self \in ProcSet |-> "read"]
read(self) == /\ pc[self] = "read"
/\ x' = [x EXCEPT ![self] = total]
/\ pc' = [pc EXCEPT ![self] = "inc"]
/\ total' = total
inc(self) == /\ pc[self] = "inc"
/\ x' = [x EXCEPT ![self] = x[self] + 1]
/\ pc' = [pc EXCEPT ![self] = "save"]
/\ total' = total
save(self) == /\ pc[self] = "save"
/\ total' = x[self]
/\ pc' = [pc EXCEPT ![self] = "Done"]
/\ x' = x
Proc(self) == read(self) \/ inc(self) \/ save(self)
Next == (\E self \in 1..N: Proc(self))
\/ (* Disjunct to prevent deadlock on termination *)
((\A self \in ProcSet: pc[self] = "Done") /\ UNCHANGED vars)
Spec == Init /\ [][Next]_vars
Termination == <>(\A self \in ProcSet: pc[self] = "Done")
\* END TRANSLATION
AlgoOK == (\A self \in ProcSet: pc[self] = "Done") => total = N
=============================================================================
\* Modification History
\* Last modified Thu Nov 30 18:40:12 PST 2017 by satya
\* Created Thu Nov 30 17:59:30 PST 2017 by satya