From e5e24f0844801d989ad156e740388a868e898580 Mon Sep 17 00:00:00 2001
From: Vadzim Dambrouski <vadzim.dambrouski@promwad.com>
Date: Thu, 9 Nov 2017 22:04:17 +0300
Subject: [PATCH] What if tsan is right?

---
 src/ring_buffer/spsc.rs | 2 +-
 tests/tsan.rs           | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ring_buffer/spsc.rs b/src/ring_buffer/spsc.rs
index 082aab7..4260bae 100644
--- a/src/ring_buffer/spsc.rs
+++ b/src/ring_buffer/spsc.rs
@@ -88,8 +88,8 @@ where
         let n = rb.capacity() + 1;
         let buffer: &mut [T] = unsafe { rb.buffer.as_mut() };
 
-        let head = rb.head.load_relaxed();
         let tail = rb.tail.load_relaxed();
+        let head = rb.head.load_acquire();
         let next_tail = (tail + 1) % n;
         if next_tail != head {
             // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We
diff --git a/tests/tsan.rs b/tests/tsan.rs
index 9fbcb8d..07def14 100644
--- a/tests/tsan.rs
+++ b/tests/tsan.rs
@@ -87,7 +87,7 @@ fn contention() {
             scope.execute(move || {
                 let mut sum: u32 = 0;
 
-                for i in 0..N {
+                for i in 0..(2*N) {
                     let i = i as u8;
                     sum = sum.wrapping_add(i as u32);
                     while let Err(_) = p.enqueue(i) {}
@@ -99,7 +99,7 @@ fn contention() {
             scope.execute(move || {
                 let mut sum: u32 = 0;
 
-                for _ in 0..N {
+                for _ in 0..(2*N) {
                     loop {
                         match c.dequeue() {
                             Some(v) => {
-- 
GitLab