-
Notifications
You must be signed in to change notification settings - Fork 0
/
threads.tla
67 lines (47 loc) · 1.87 KB
/
threads.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
------------------------------ MODULE threads ------------------------------
EXTENDS Integers
CONSTANT NumThreads
Threads == 1..NumThreads \* Set of {1, 2, ... NumThreads}
\* Anything inside the `(* --algorithm` is "PlusCal"
(* --algorithm threads
variables
x = 0; \* global
process thread \in Threads \* One thread process per element of Threads
variables tmp = 0; \* tmp is local to each process
begin
Get: \* "Label". Each process Gets then Incs, but other threads can interrupt
tmp := x;
Inc:
x := tmp + 1;
end process;
end algorithm; *)
\* Everything in BEGIN TRANSLATION is automatically generated from the pluscal
\* BEGIN TRANSLATION - the hash of the PCal code: PCal-2cfd730c7e541cfac6a18f77d5288391
VARIABLES x, pc, tmp
vars == << x, pc, tmp >>
ProcSet == (Threads)
Init == (* Global variables *)
/\ x = 0
(* Process thread *)
/\ tmp = [self \in Threads |-> 0]
/\ pc = [self \in ProcSet |-> "Get"]
Get(self) == /\ pc[self] = "Get"
/\ tmp' = [tmp EXCEPT ![self] = x]
/\ pc' = [pc EXCEPT ![self] = "Inc"]
/\ x' = x
Inc(self) == /\ pc[self] = "Inc"
/\ x' = tmp[self] + 1
/\ pc' = [pc EXCEPT ![self] = "Done"]
/\ tmp' = tmp
thread(self) == Get(self) \/ Inc(self)
(* Allow infinite stuttering to prevent deadlock on termination. *)
Terminating == /\ \A self \in ProcSet: pc[self] = "Done"
/\ UNCHANGED vars
Next == (\E self \in Threads: thread(self))
\/ Terminating
Spec == Init /\ [][Next]_vars
Termination == <>(\A self \in ProcSet: pc[self] = "Done")
\* END TRANSLATION - the hash of the generated TLA code (remove to silence divergence warnings): TLA-3b1540a4627b3d3586cb172c60eb0c0c
\* Normally there'd be invariants and properties described here, but since we're just
\* using this to generate the state graph, we don't need any
====