Skip to content

Commit

Permalink
Merge pull request #260 from Amanieu/rwlock_ordering
Browse files Browse the repository at this point in the history
RawRwLock::wait_for_readers needs an Acquire to synchronize with unlock_shared
  • Loading branch information
Amanieu committed Nov 17, 2020
2 parents ecfe20b + ded782f commit c8dfa97
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/raw_rwlock.rs
Expand Up @@ -970,11 +970,11 @@ impl RawRwLock {
// At this point WRITER_BIT is already set, we just need to wait for the
// remaining readers to exit the lock.
let mut spinwait = SpinWait::new();
let mut state = self.state.load(Ordering::Relaxed);
let mut state = self.state.load(Ordering::Acquire);
while state & READERS_MASK != 0 {
// Spin a few times to wait for readers to exit
if spinwait.spin() {
state = self.state.load(Ordering::Relaxed);
state = self.state.load(Ordering::Acquire);
continue;
}

Expand Down Expand Up @@ -1019,7 +1019,7 @@ impl RawRwLock {
// since a previous writer timing-out could have allowed
// another reader to sneak in before we parked.
ParkResult::Unparked(_) | ParkResult::Invalid => {
state = self.state.load(Ordering::Relaxed);
state = self.state.load(Ordering::Acquire);
continue;
}

Expand Down

0 comments on commit c8dfa97

Please sign in to comment.