Skip to content

Commit

Permalink
Merge pull request rust-lang#221 from dwrensha/seq-cst-explain
Browse files Browse the repository at this point in the history
Add a comment explaining that we depend on SeqCst ordering.
  • Loading branch information
alexcrichton committed Nov 1, 2016
2 parents 1993896 + 5351395 commit b17b261
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate core;

use self::core::cell::UnsafeCell;
use self::core::ops::{Deref, DerefMut};
use self::core::sync::atomic::Ordering::{SeqCst};
use self::core::sync::atomic::Ordering::SeqCst;
use self::core::sync::atomic::AtomicBool;

/// A "mutex" around a value, similar to `std::sync::Mutex<T>`.
Expand Down
6 changes: 6 additions & 0 deletions src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ impl<T> Drop for Complete<T> {
// blocking to see if it succeeded. In the latter case we don't need to
// wake up anyone anyway. So in both cases it's ok to ignore the `None`
// case of `try_lock` and bail out.
//
// The first case crucially depends on `Lock` using `SeqCst` ordering
// under the hood. If it instead used `Release` / `Acquire` ordering,
// then it would not necessarily synchronize with `inner.complete`
// and deadlock might be possible, as was observed in
// https://github.com/alexcrichton/futures-rs/pull/219.
self.inner.complete.store(true, SeqCst);
if let Some(mut slot) = self.inner.rx_task.try_lock() {
if let Some(task) = slot.take() {
Expand Down

0 comments on commit b17b261

Please sign in to comment.