----------------------------- MODULE ParamLock ------------------------------ (* Lesson 5: MiniLock with any number of orders. Orders is a parameter. *) (* An order may start only while no order has started (the lock). *) CONSTANT Orders VARIABLE st \* st[o] is the status of order o vars == <> Status == {"idle", "open", "done"} TypeOK == st \in [Orders -> Status] Started(x) == x \in {"open", "done"} Init == st = [o \in Orders |-> "idle"] Checkout(o) == /\ st[o] = "idle" /\ \A p \in Orders : ~Started(st[p]) /\ st' = [st EXCEPT ![o] = "open"] Callback(o) == /\ st[o] = "open" /\ st' = [st EXCEPT ![o] = "done"] Next == \E o \in Orders : Checkout(o) \/ Callback(o) Spec == Init /\ [][Next]_vars \* Business rule: at most one order (hence one subscription) is done. AtMostOneDone == \A p, q \in Orders : (st[p] = "done" /\ st[q] = "done") => p = q \* Inductive invariant: at most one order has started. Inv == TypeOK /\ \A p, q \in Orders : (Started(st[p]) /\ Started(st[q])) => p = q =============================================================================