Skip to content

Instantly share code, notes, and snippets.

@gterzian
Last active June 25, 2024 17:29
Show Gist options
  • Save gterzian/d75d6544fd88ebb18caa3cf934e60ab7 to your computer and use it in GitHub Desktop.
Save gterzian/d75d6544fd88ebb18caa3cf934e60ab7 to your computer and use it in GitHub Desktop.
----------------------------- MODULE EventLoop -----------------------------
EXTENDS FiniteSets, Naturals
VARIABLES task_counter, step_counter
CONSTANT N
----------------------------------------------------------------------------
Count == 0..N
Task == {"Other", "Update"}
Step == {"A", "B"}
TypeOk == /\ task_counter \in [Task -> Count]
/\ step_counter \in [Step -> Count]
StepAtomicUpdateInvariant == \A a, b \in Step:
/\ step_counter[a] = step_counter[b]
/\ step_counter[a] = task_counter["Update"]
----------------------------------------------------------------------------
Init == /\ task_counter = [t \in Task |-> 0]
/\ step_counter = [s \in Step |-> 0]
RunOtherTask(t) == /\ task_counter[t] < N
/\ t = "Other"
/\ task_counter' = [task_counter EXCEPT ![t] = @+1]
/\ UNCHANGED<<step_counter>>
RunUpdateTask(t) == /\ task_counter[t] < N
/\ t = "Update"
/\ step_counter' = [s \in Step |-> step_counter[s] + 1]
/\ task_counter' = [task_counter EXCEPT ![t] = @+1]
Stop == /\ \A t \in Task: task_counter[t] = N
/\ UNCHANGED<<task_counter, step_counter>>
Next == \/ \E t \in Task: \/ RunOtherTask(t)
\/ RunUpdateTask(t)
\/ Stop
Spec == Init /\ [][Next]_<<task_counter, step_counter>>
----------------------------------------------------------------------------
THEOREM Spec => [](TypeOk /\ StepAtomicUpdateInvariant)
============================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment