-
Notifications
You must be signed in to change notification settings - Fork 2
/
Increment.tla
67 lines (51 loc) · 1.83 KB
/
Increment.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
66
67
------------------------------- MODULE Increment -------------------------------
EXTENDS Naturals, TLC
CONSTANT N
ASSUME N \in Nat \{0}
Procs == 1..N
\* N processes all increment a shared variable x by (1) reading it, assigning the read value +1 to local variable
\* y and (2) assigning y back to x.
\* Unless the read and write of x is done atomically, the Correctness property below will fail.
\* To make this code incorrect, use a second label l2 in front of the assignment from y to x.
(*
--algorithm Incr {
variables x=0;
process (p \in Procs)
variables y=0;
{
\* both assignments need to be done atomically; l1 ensures that
l1:
y :=x+1;
x := y; \* Incorrect: l2: x := y;
print <<self,pc,x>>;
}
}
*)
\* BEGIN TRANSLATION
VARIABLES x, pc, y
vars == << x, pc, y >>
ProcSet == (Procs)
Init == (* Global variables *)
/\ x = 0
(* Process p *)
/\ y = [self \in Procs |-> 0]
/\ pc = [self \in ProcSet |-> "l1"]
l1(self) == /\ pc[self] = "l1"
/\ y' = [y EXCEPT ![self] = x+1]
/\ x' = y'[self]
/\ PrintT(<<self,pc,x'>>)
/\ pc' = [pc EXCEPT ![self] = "Done"]
p(self) == l1(self)
Next == (\E self \in Procs: p(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
AllDone == \A self \in Procs: pc[self] = "Done"
Correctness == [](AllDone => x = N)
=============================================================================
\* Modification History
\* Last modified Tue Jan 10 09:23:07 CET 2017 by bela
\* Last modified Fri Feb 13 10:00:32 EST 2015 by nrla
\* Created Wed Feb 11 18:05:23 EST 2015 by nrla