Created
April 19, 2017 23:04
-
-
Save hwayne/ed8f18a0458819f15ab638d561986d4e to your computer and use it in GitHub Desktop.
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, Sequences, TLC, FiniteSets | |
(* --algorithm deadlock | |
variable mq = <<>>; | |
macro add_message(msg) begin | |
await Len(mq) < 5; | |
mq := Append(mq, <<msg>>); | |
end macro | |
procedure garbage_collector() begin | |
GC: | |
either | |
Add: | |
add_message(<<self, "gc">>); | |
return; | |
or | |
skip; | |
return; | |
end either; | |
end procedure; | |
process reader = "reader" | |
begin | |
Read: | |
while TRUE do | |
await Len(mq) /= 0; | |
mq := Tail(mq); | |
call garbage_collector(); | |
end while; | |
end process; | |
process writer = "writer" | |
begin | |
Write: | |
while TRUE do | |
add_message("write"); | |
end while; | |
end process; | |
end algorithm; | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment