Skip to content

Commit

Permalink
Switch mpsc sender count to use SeqCst
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche committed Dec 2, 2016
1 parent dd8df92 commit ed3b268
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use std::any::Any;
use std::error::Error;
use std::fmt;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{SeqCst, Relaxed};
use std::sync::atomic::Ordering::SeqCst;
use std::sync::{Arc, Mutex};
use std::thread;
use std::usize;
Expand Down Expand Up @@ -510,7 +510,7 @@ impl<T> Clone for Sender<T> {
// Since this atomic op isn't actually guarding any memory and we don't
// care about any orderings besides the ordering on the single atomic
// variable, a relaxed ordering is acceptable.
let mut curr = self.inner.num_senders.load(Relaxed);
let mut curr = self.inner.num_senders.load(SeqCst);

loop {
// If the maximum number of senders has been reached, then fail
Expand All @@ -521,7 +521,7 @@ impl<T> Clone for Sender<T> {
debug_assert!(curr < self.inner.max_senders());

let next = curr + 1;
let actual = self.inner.num_senders.compare_and_swap(curr, next, Relaxed);
let actual = self.inner.num_senders.compare_and_swap(curr, next, SeqCst);

// The ABA problem doesn't matter here. We only care that the
// number of senders never exceeds the maximum.
Expand All @@ -541,7 +541,7 @@ impl<T> Clone for Sender<T> {
impl<T> Drop for Sender<T> {
fn drop(&mut self) {
// Ordering between variables don't matter here
let prev = self.inner.num_senders.fetch_sub(1, Relaxed);
let prev = self.inner.num_senders.fetch_sub(1, SeqCst);

if prev == 1 {
let _ = self.do_send(None, false);
Expand Down

1 comment on commit ed3b268

@NeoLegends
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found this commit because the comments are outdated. Might wanna fix those.

Please sign in to comment.