Last active
April 14, 2023 20:29
-
-
Save hwayne/f36731b9185f5f6b87255a0e828f9a91 to your computer and use it in GitHub Desktop.
Formal Methods Example Spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXTENDS Integers, TLC, Sequences | |
CONSTANTS Devices | |
(* --algorithm BatchInstall | |
variables | |
AppScope \in [Devices -> {0, 1}]; | |
Installs \in [Devices -> BOOLEAN]; | |
batch_pool = {}; | |
lock = FALSE; | |
define | |
PoolNotEmpty == batch_pool # {} | |
end define | |
procedure ChangeAppScope() | |
variables cache; | |
begin | |
GetLock: | |
await ~lock; | |
lock := TRUE; | |
Cache: | |
cache := batch_pool; | |
Filter: | |
cache := cache \intersect {d \in Devices: AppScope[d] = 0}; | |
Add: | |
AppScope := [d \in Devices |-> | |
IF d \in cache THEN AppScope[d] + 1 | |
ELSE AppScope[d] | |
]; | |
Clean: | |
batch_pool := batch_pool \ cache; | |
lock := FALSE; | |
return; | |
end procedure | |
fair process SyncDevice \in Devices | |
begin | |
Sync: | |
if Installs[self] then | |
batch_pool := batch_pool \union {self}; | |
end if; | |
if PoolNotEmpty then | |
either | |
call ChangeAppScope(); | |
or | |
skip; | |
end either; | |
end if; | |
end process; | |
fair process TimeLoop = 0 | |
begin | |
Start: | |
while TRUE do | |
await PoolNotEmpty; | |
call ChangeAppScope(); | |
end while; | |
end process | |
end algorithm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment