Skip to content

Instantly share code, notes, and snippets.

@hwayne
Created August 15, 2023 20:29
Show Gist options
  • Save hwayne/3cf0d509bdbd12a0bce298277ea40561 to your computer and use it in GitHub Desktop.
Save hwayne/3cf0d509bdbd12a0bce298277ea40561 to your computer and use it in GitHub Desktop.
Demonstration of bug in distributed lock
CONSTANTS
Threads = {t1, t2, t3}
NULL = NULL
SPECIFICATION Spec
PROPERTY NoRaces
---- MODULE distlock ----
EXTENDS TLC, Integers, Sequences
CONSTANT Threads, NULL
Range(f) == {f[x] : x \in DOMAIN f}
(*--algorithm distlock
variable
data = 0;
lock = NULL;
process writeData \in Threads
variable tmp = -1;
begin
GetLock:
await lock = NULL;
lock := self;
readData:
tmp := data;
calcData:
tmp := tmp + 1;
writeData:
data := tmp;
ReleaseLock:
lock := NULL;
end process;
process clock = "clock"
begin
ExpireLock:
lock := NULL;
end process;
end algorithm; *)
====
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment