Skip to content

Commit f0bf738

Browse files
committed
Add small improvements to specs.
- Add comment on 'Multicast' behaviour. - Add ASSUME for MaxPublished constant. - Add comment on the usage of the 'consumed' variable. - Remove WF from write actions. - Remove bounding of model happening in BeginWrite action. Use a State constraint instead. Use suggestion for liveliness property. - (The last two items are not done yet for the MPMC spec - it's less straight forward to do because of the multiple producers behaviour.) Signed-off-by: Nicholas Schultz-Møller <[email protected]>
1 parent 7ebd914 commit f0bf738

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@
498498
"ignore deadlock"
499499
],
500500
"result": "success",
501-
"distinctStates": 8153,
502-
"totalStates": 26481,
503-
"stateDepth": 81
501+
"distinctStates": 8496,
502+
"totalStates": 28049,
503+
"stateDepth": 82
504504
}
505505
]
506506
},

specifications/Disruptor/Disruptor_MPMC.tla

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(* *)
99
(* The model also verifies that no data races occur between the producers *)
1010
(* and consumers and that all consumers eventually read all published *)
11-
(* values. *)
11+
(* values (in a Multicast fashion - i.e. all consumers read all events). *)
1212
(***************************************************************************)
1313

1414
EXTENDS Integers, FiniteSets, Sequences
@@ -22,16 +22,19 @@ CONSTANTS
2222

2323
ASSUME Writers /= {}
2424
ASSUME Readers /= {}
25-
ASSUME Size \in Nat \ {0}
25+
ASSUME Size \in Nat \ {0}
26+
ASSUME MaxPublished \in Nat \ {0}
2627

2728
VARIABLES
2829
ringbuffer,
2930
next_sequence, (* Shared counter for claiming a sequence for a Writer. *)
3031
claimed_sequence, (* Claimed sequence by each Writer. *)
3132
published, (* Encodes whether each slot is published. *)
3233
read, (* Read Cursors. One per Reader. *)
33-
consumed, (* Sequence of all read events by the Readers. *)
34-
pc (* Program Counter for each Writer/Reader. *)
34+
pc, (* Program Counter for each Writer/Reader. *)
35+
consumed (* Sequence of all read events by the Readers. *)
36+
(* This is a history variable used for liveliness *)
37+
(* checking. *)
3538

3639
vars == <<
3740
ringbuffer,

specifications/Disruptor/Disruptor_SPMC.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ INVARIANTS
1515
PROPERTIES
1616
Liveliness
1717

18+
CONSTRAINT
19+
StateConstraint
20+
1821
CHECK_DEADLOCK
1922
FALSE

specifications/Disruptor/Disruptor_SPMC.tla

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(* *)
99
(* The model also verifies that no data races occur between the producer *)
1010
(* and consumers and that all consumers eventually read all published *)
11-
(* values. *)
11+
(* values (in a Multicast fashion - i.e. all consumers read all events). *)
1212
(* *)
1313
(* To see a data race, try and run the model with two producers. *)
1414
(***************************************************************************)
@@ -24,14 +24,17 @@ CONSTANTS
2424

2525
ASSUME Writers /= {}
2626
ASSUME Readers /= {}
27-
ASSUME Size \in Nat \ {0}
27+
ASSUME Size \in Nat \ {0}
28+
ASSUME MaxPublished \in Nat \ {0}
2829

2930
VARIABLES
3031
ringbuffer,
3132
published, (* Write cursor. One for the producer. *)
3233
read, (* Read cursors. One per consumer. *)
33-
consumed, (* Sequence of all read events by the Readers. *)
34-
pc (* Program Counter of each Writer/Reader. *)
34+
pc, (* Program Counter of each Writer/Reader. *)
35+
consumed (* Sequence of all read events by the Readers. *)
36+
(* This is a history variable used for liveliness *)
37+
(* checking. *)
3538

3639
vars == <<
3740
ringbuffer,
@@ -73,7 +76,6 @@ BeginWrite(writer) ==
7376
IN
7477
\* Are we clear of all consumers? (Potentially a full cycle behind).
7578
/\ min_read >= next - Size
76-
/\ next < MaxPublished
7779
/\ Transition(writer, Access, Advance)
7880
/\ Buffer!Write(index, writer, next)
7981
/\ UNCHANGED << consumed, published, read >>
@@ -132,14 +134,18 @@ Next ==
132134
\/ \E r \in Readers : EndRead(r)
133135

134136
Fairness ==
135-
/\ \A w \in Writers : WF_vars(BeginWrite(w))
136-
/\ \A w \in Writers : WF_vars(EndWrite(w))
137137
/\ \A r \in Readers : WF_vars(BeginRead(r))
138138
/\ \A r \in Readers : WF_vars(EndRead(r))
139139

140140
Spec ==
141141
Init /\ [][Next]_vars /\ Fairness
142142

143+
(***************************************************************************)
144+
(* State constraint to bound model: *)
145+
(***************************************************************************)
146+
147+
StateConstraint == published < MaxPublished
148+
143149
(***************************************************************************)
144150
(* Invariants: *)
145151
(***************************************************************************)
@@ -159,6 +165,7 @@ NoDataRaces == Buffer!NoDataRaces
159165

160166
(* Eventually always, consumers must have read all published values. *)
161167
Liveliness ==
162-
<>[] (\A r \in Readers : consumed[r] = [i \in 1..MaxPublished |-> i - 1])
168+
\A r \in Readers : \A i \in 0 .. (MaxPublished - 1) :
169+
<>[](i \in 0 .. published => Len(consumed[r]) >= i + 1 /\ consumed[r][i + 1] = i)
163170

164-
=============================================================================
171+
=============================================================================

0 commit comments

Comments
 (0)