-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\* Add statements after this line. | ||
SPECIFICATION Spec | ||
CONSTANTS | ||
Producers = {p1,p2} | ||
Consumers = {c1,c2} | ||
BufCapacity = 1 | ||
\* generate dot file: add "-dump dot trans.dot" to TLC options | ||
\* (=> extension settings) | ||
INVARIANT Inv |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--------------------------- MODULE Bug2750 --------------------------- | ||
(***************************************************************************) | ||
(* Original problem and spec by Michel Charpentier *) | ||
(* http://www.cs.unh.edu/~charpov/programming-tlabuffer.html *) | ||
(***************************************************************************) | ||
EXTENDS Naturals, Sequences | ||
|
||
CONSTANTS | ||
\* @type: Set(PROC); | ||
Producers, (* the (nonempty) set of producers *) | ||
\* @type: Set(PROC); | ||
Consumers, (* the (nonempty) set of consumers *) | ||
\* @type: Int; | ||
BufCapacity (* the maximum number of messages in the bounded buffer *) | ||
|
||
ASSUME Assumption == | ||
/\ Producers # {} (* at least one producer *) | ||
/\ Consumers # {} (* at least one consumer *) | ||
/\ Producers \intersect Consumers = {} (* no thread is both consumer and producer *) | ||
/\ BufCapacity \in (Nat \ {0}) (* buffer capacity is at least 1 *) | ||
|
||
----------------------------------------------------------------------------- | ||
|
||
VARIABLES | ||
\* @type: Seq(PROC); | ||
buffer, | ||
\* @type: Set(PROC); | ||
waitP, | ||
\* @type: Set(PROC); | ||
waitC | ||
|
||
(* define statement *) | ||
isfull(b) == Len(b) = BufCapacity | ||
isempty(b) == Len(b) = 0 | ||
|
||
\* @type: << Seq(PROC), Set(PROC), Set(PROC) >>; | ||
vars == << buffer, waitP, waitC >> | ||
|
||
ProcSet == (Producers) \cup (Consumers) | ||
|
||
Init == (* Global variables *) | ||
/\ buffer = << >> | ||
/\ waitP = {} | ||
/\ waitC = {} | ||
|
||
p(self) == /\ (self \notin waitP) | ||
/\ IF isfull(buffer) | ||
THEN /\ IF self \in Producers | ||
THEN /\ waitP' = (waitP \union {self}) | ||
/\ waitC' = waitC | ||
ELSE /\ waitC' = (waitC \union {self}) | ||
/\ waitP' = waitP | ||
/\ UNCHANGED buffer | ||
ELSE /\ buffer' = Append(buffer, self) | ||
/\ IF waitC # {} | ||
THEN /\ \E t \in waitC: | ||
waitC' = waitC \ {t} | ||
ELSE /\ TRUE | ||
/\ waitC' = waitC | ||
/\ waitP' = waitP | ||
|
||
c(self) == /\ (self \notin waitC) | ||
/\ IF isempty(buffer) | ||
THEN /\ IF self \in Producers | ||
THEN /\ waitP' = (waitP \union {self}) | ||
/\ waitC' = waitC | ||
ELSE /\ waitC' = (waitC \union {self}) | ||
/\ waitP' = waitP | ||
/\ UNCHANGED buffer | ||
ELSE /\ buffer' = Tail(buffer) | ||
/\ IF waitP # {} | ||
THEN /\ \E t \in waitP: | ||
waitP' = waitP \ {t} | ||
ELSE /\ TRUE | ||
/\ waitP' = waitP | ||
/\ waitC' = waitC | ||
|
||
Next == (\E self \in Producers: p(self)) | ||
\/ (\E self \in Consumers: c(self)) | ||
|
||
Spec == Init /\ [][Next]_vars | ||
|
||
\* END TRANSLATION | ||
|
||
Inv == ~(waitP = Producers /\ waitC = Consumers) | ||
|
||
============================================================================= |