Skip to content

Instantly share code, notes, and snippets.

@hwayne
Created February 2, 2017 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwayne/1a58b964c10b3a067170bb996e47a78e to your computer and use it in GitHub Desktop.
Save hwayne/1a58b964c10b3a067170bb996e47a78e to your computer and use it in GitHub Desktop.
---- MODULE logger ----
EXTENDS Integers, TLC, Sequences
Files == { "a" }
FileStruct == [ requested : BOOLEAN, uploaded : {FALSE}, logged : {FALSE}, downloaded : {FALSE}]
Range(F) == { F[x]: x \in DOMAIN F }
(* --algorithm logger
variables files \in [Files -> FileStruct];
define
FileProc(proc) == [ f : Files, p : {proc} ]
end define;
process upload \in FileProc("upload")
begin
Upload:
if files[self.f].requested then
files[self.f].uploaded := TRUE
end if
end process;
process log \in FileProc("log")
begin
Log:
await files[self.f].uploaded;
files[self.f].logged := TRUE
end process;
process download \in FileProc("download")
begin
Download:
await files[self.f].uploaded;
files[self.f].downloaded := TRUE ||
files[self.f].uploaded := FALSE
end process;
end algorithm; *)
\* BEGIN TRANSLATION
\* END TRANSLATION
DownloadInvariant ==
\A f \in Files:
/\ files[f].downloaded => files[f].requested
/\ files[f].downloaded => ~files[f].uploaded
LoggingInvariant ==
\A f \in Files:
/\ files[f].downloaded => files[f].logged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment