// ----------------------------------------------------------------- // allocator.txt: a resource allocator // Concrete Abstractions: Concurrent Systems // (c) 2020, Wolfgang Schreiner, RISC, JKU Linz, Austria // ----------------------------------------------------------------- // See Stephan Merz: "The Specification Language TLA+", In: Bjørner D., // Henson M.C: Logics of Specification Languages, Springer, 2008. val C:ℕ; // number of clients val R:ℕ; // number of resources axiom notNull ⇔ C > 0 ∧ R > 0; type Client = ℕ[C-1]; type Resource = ℕ[R-1]; type Position = ℕ[C]; // 0=first ... C-1=last, C=none // get position of request from client c in queue of requests fun position(c:Client,pos:Map[Client,Position]):Position = let p = pos[c] in if p < C then p else if ∀c0:Client. pos[c0] = C then 0 else 1 + max c0:Client with pos[c0] < C. pos[c0]; // remove client c from queue of requests proc remove(pos:Map[Client,Position], c:Client):Map[Client,Position] ensures ∀c0:Client. result[c0] = if c0 = c then C else if pos[c] < pos[c0] ∧ pos[c0] < C then pos[c0]-1 else pos[c0]; { var p:Map[Client,Position] = pos; for c0:Client with p[c] < p[c0] ∧ p[c0] < C do p[c0] ≔ p[c0]-1; p[c] ≔ C; return p; } // server may grant to client c resource set S pred grant(c:Client,S:Set[Resource], unsat:Map[Client,Set[Resource]], alloc:Map[Client,Set[Resource]], pos:Map[Client,Position]) ⇔ pos[c] < C ∧ S ≠ ∅[Resource] ∧ (∀r∈S. r∈unsat[c] ∧ ¬∃c0:Client. r∈alloc[c0]) ∧ (∀c0:Client with pos[c0]