Skip to content

Instantly share code, notes, and snippets.

@isaiah-perumalla
Created April 28, 2024 21:10
Show Gist options
  • Save isaiah-perumalla/3e66ea8c650bc16b803247d6e5ef9ef6 to your computer and use it in GitHub Desktop.
Save isaiah-perumalla/3e66ea8c650bc16b803247d6e5ef9ef6 to your computer and use it in GitHub Desktop.
tla_plus_concurrent_counter
VARIABLES counter, pc
(* define statement *)
AllDone == \A t \in Threads : pc[t] = "Done"
Correct == AllDone => counter = ThreadCount
VARIABLE localCounter
vars == << counter, pc, localCounter >>
ProcSet == (1..ThreadCount)
Init == (* Global variables *)
/\ counter = 0
(* Process counter_ *)
/\ localCounter = [self \in 1..ThreadCount |-> 0]
/\ pc = [self \in ProcSet |-> "Load"]
Load(self) == /\ pc[self] = "Load"
/\ localCounter' = [localCounter EXCEPT ![self] = counter]
/\ pc' = [pc EXCEPT ![self] = "Inc"]
/\ UNCHANGED counter
Inc(self) == /\ pc[self] = "Inc"
/\ counter' = localCounter[self] + 1
/\ pc' = [pc EXCEPT ![self] = "Done"]
/\ UNCHANGED localCounter
counter_(self) == Load(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 1..ThreadCount: counter_(self))
\/ Terminating
Spec == Init /\ [][Next]_vars
Termination == <>(\A self \in ProcSet: pc[self] = "Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment