Skip to content

Commit 0c6a093

Browse files
committed
Unix RwLock: avoid racy access to write_locked
1 parent 9b8f902 commit 0c6a093

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libstd/sys/unix/rwlock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use sync::atomic::{AtomicUsize, Ordering};
1414

1515
pub struct RWLock {
1616
inner: UnsafeCell<libc::pthread_rwlock_t>,
17-
write_locked: UnsafeCell<bool>,
17+
write_locked: UnsafeCell<bool>, // guarded by the `inner` RwLock
1818
num_readers: AtomicUsize,
1919
}
2020

@@ -52,7 +52,7 @@ impl RWLock {
5252
// allow that because it could lead to aliasing issues.
5353
if r == libc::EAGAIN {
5454
panic!("rwlock maximum reader count exceeded");
55-
} else if r == libc::EDEADLK || *self.write_locked.get() {
55+
} else if r == libc::EDEADLK || (r == 0 && *self.write_locked.get()) {
5656
if r == 0 {
5757
self.raw_unlock();
5858
}

0 commit comments

Comments
 (0)