Skip to content

Commit afaafb5

Browse files
committed
Fix bug
1 parent bcc1db6 commit afaafb5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

text/2018-01-07-deque-proof.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn resize(&self, cap_new) {
172172
'L308: guard.defer(move || old.into_owned());
173173
}
174174

175-
pub fn steal(&self) -> Retry<T> {
175+
pub fn steal(&self) -> Steal<T> {
176176
'L401: let mut t = self.top.load(Relaxed);
177177

178178
'L402: let guard = epoch::pin_fence(); // epoch::pin(), but issue fence(SeqCst) even if it is re-entering
@@ -183,13 +183,12 @@ pub fn steal(&self) -> Retry<T> {
183183
'L405: let buffer = self.buffer.load(Acquire, &guard);
184184
'L406: let value = buffer.read(t % buffer.get_capacity(), Relaxed);
185185

186-
'L407: match self.top.compare_and_swap_weak(t, t + 1, Release) {
187-
'L408: Ok(_) => return Data(value),
188-
'L409: Err(t_old) => {
189-
'L410: mem::forget(value);
190-
'L411: return Retry;
191-
'L412: }
192-
'L413: }
186+
'L407: if self.top.compare_and_swap_weak(t, t + 1, Release, Relaxed).is_err() {
187+
'L408: mem::forget(value);
188+
'L409: return Retry;
189+
'L410: }
190+
191+
'L411: Data(value)
193192
}
194193
```
195194

@@ -737,7 +736,7 @@ each case of `I_i`.
737736
write to `bottom` at `'L110` to `I_i`'s read from `bottom` at `'L403`. Thus we have `w <= y`
738737
because `I_i` reads `top = y` once more at `'L407`, `WB_(l+1)` is coherence-after-or `WB_(k+1)`,
739738
and the value `v` that `O_k` wrote to the buffer at `'L109` should be acknowledged by `I_i` at
740-
`'L409`. Also, we have `view_beginning(O_k) <= view_end(I_i)`, as required by `(SYNC)`.
739+
`'L406`. Also, we have `view_beginning(O_k) <= view_end(I_i)`, as required by `(SYNC)`.
741740

742741
+ Case `l <= k`.
743742

@@ -989,17 +988,17 @@ follows:
989988
- `'L102` can be just plain load: `'L109` is the only synchronization target, and they have RW ctrl
990989
dependency.
991990

992-
- `'L408` can be just plain load: `'L409` is the only synchronization target, and they have RR addr
991+
- `'L405` can be just plain load: `'L406` is the only synchronization target, and they have RR addr
993992
dependency. In an ideal world, this synchronizing dependency should be expressible in C11 using
994993
the `Consume` ordering.
995994

996-
- `'L404` can be just plain load, but `isync/isb` should be inserted right before `'L408`: `'L408`'s
997-
read, `'L409`'s read, `'L407`'s read/write, and the end view of `steal()` in the successful case
995+
- `'L404` can be just plain load, but `isync/isb` should be inserted right before `'L405`: `'L405`'s
996+
read, `'L406`'s read, `'L407`'s read/write, and the end view of `steal()` in the successful case
998997
are the synchronization targets, and they have RR/RW ctrl+`isync/isb` dependency.
999998

1000999
We believe [this paper][chase-lev-weak] has a bug in their ARMv7 implementation of Chase-Lev
10011000
deque. Roughly speaking, they used a plain load for `'L404`, and put ctrl+`isync/isb` right after
1002-
`'L409`. But in that case, the reads at `'L405-'L406` can be reordered before `'L404`. See
1001+
`'L406`. But in that case, the reads at `'L405-'L406` can be reordered before `'L404`. See
10031002
the [this tutorial][arm-power] §4.2 on [the MP+dmb+ctrl litmus test][mp+dmb+ctrl] for more
10041003
details.
10051004

0 commit comments

Comments
 (0)