Created
April 19, 2022 13:56
-
-
Save vjabrayilov/aa446420ea5bfb3c6147a80d5223149f 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 Naturals, Sequences | |
CONSTANTS Producers, | |
Consumers, | |
BufCapacity, | |
Data | |
ASSUME /\ Producers # {} | |
/\ Consumers # {} | |
/\ Producers \intersect Consumers = {} | |
/\ BufCapacity > 0 | |
/\ Data # {} | |
-------------------------------------------------------------------------------- | |
VARIABLES buffer, | |
waitSet | |
Participants == Producers \union Consumers | |
RunningThreads == Participants \ waitSet | |
TypeInv == /\ buffer \in Seq(Data) | |
/\ Len(buffer) \in 0..BufCapacity | |
/\ waitSet \subseteq Participants | |
Notify == IF waitSet # {} | |
THEN \E x \in waitSet : waitSet' = waitSet \ {x} | |
ELSE UNCHANGED waitSet | |
NotifyAll == waitSet' = {} | |
Wait(t) == waitSet' = waitSet \union {t} | |
-------------------------------------------------------------------------------- | |
Init == buffer = <<>> /\ waitSet = {} | |
Put(t,m) == IF Len(buffer) < BufCapacity | |
THEN /\ buffer' = Append(buffer, m) | |
/\ Notify | |
ELSE /\ Wait(t) | |
/\ UNCHANGED buffer | |
Get(t) == IF Len(buffer) > 0 | |
THEN /\ buffer' = Tail(buffer) | |
/\ Notify (* Notify vs NotifyAll *) | |
ELSE /\ Wait(t) | |
/\ UNCHANGED buffer | |
Next == \E t \in RunningThreads : \/ t \in Producers /\ \E m \in Data : Put(t,m) | |
\/ t \in Consumers /\ Get(t) | |
Prog == Init /\ [][Next]_<<buffer, waitSet>> | |
-------------------------------------------------------------------------------- | |
NoDeadlock == [](RunningThreads # {}) | |
THEOREM Prog => []TypeInv /\ NoDeadlock | |
============================================================================= | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment