--------------------------- MODULE QuestionWakeKeys --------------------------- (***************************************************************************) (* DelegatedTaskQuestionReactor: which key orders a question's wake and *) (* its task's cancel. *) (* *) (* The stream carries, in order: *) (* W: child C's question is pending -> dispatch a wake message to *) (* parent P (one step under P's dispatch lock). *) (* X: the task settled -> read P's queued runs, then cancel the queued *) (* wake it found (the cancel is one step under P's dispatch lock). *) (* An external holder (a long send) holds P's lock first, then releases. *) (* *) (* Mode "Sequential": main; X starts after W finishes. *) (* Mode "ByParent": the runner keys W and X by P; X starts after W. *) (* Mode "ByChild": the runner keys W by C and X by P; they overlap. *) (***************************************************************************) EXTENDS Naturals CONSTANTS Mode ASSUME Mode \in {"Sequential", "ByParent", "ByChild"} VARIABLES extHolds, \* the external holder still holds P's lock w, \* W: "wait" (for P's lock) or "done" x, \* X: "idle", "read" (found recorded), or "done" found, \* what X's read saw queued \* a wake message sits in P's queue vars == <> Init == /\ extHolds = TRUE /\ w = "wait" /\ x = "idle" /\ found = FALSE /\ queued = FALSE \* Same key: the runner starts X only after W. ByChild has no such edge. XMayStart == Mode = "ByChild" \/ w = "done" ExtRelease == /\ extHolds /\ extHolds' = FALSE /\ UNCHANGED <> WDispatch == /\ w = "wait" /\ ~extHolds /\ w' = "done" /\ queued' = TRUE /\ UNCHANGED <> XRead == /\ x = "idle" /\ XMayStart /\ x' = "read" /\ found' = queued /\ UNCHANGED <> XCancel == /\ x = "read" /\ ~extHolds /\ x' = "done" /\ queued' = (queued /\ ~found) /\ UNCHANGED <> Done == /\ w = "done" /\ x = "done" /\ UNCHANGED vars Next == ExtRelease \/ WDispatch \/ XRead \/ XCancel \/ Done Spec == Init /\ [][Next]_vars /\ WF_vars(ExtRelease) /\ WF_vars(WDispatch) /\ WF_vars(XRead) /\ WF_vars(XCancel) ----------------------------------------------------------------------------- \* Once both reactions ran, no wake for the settled task is left queued. NoStaleWake == (w = "done" /\ x = "done") => ~queued BothRun == <>(w = "done" /\ x = "done") =============================================================================