Skip to content

Commit df4457e

Browse files
author
Austin Kiekintveld
authored
Relax memory ordering used in SameMutexCheck
`SameMutexCheck` only requires atomicity for `self.addr`, but does not need ordering of other memory accesses in either the success or failure case. Using `Relaxed`, the code still correctly handles the case when two threads race to store an address.
1 parent 4dd8b42 commit df4457e

File tree

1 file changed

+1
-1
lines changed
  • library/std/src/sys_common/condvar

1 file changed

+1
-1
lines changed

library/std/src/sys_common/condvar/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl SameMutexCheck {
2424
}
2525
pub fn verify(&self, mutex: &MovableMutex) {
2626
let addr = mutex.raw() as *const imp::Mutex as *const () as *mut _;
27-
match self.addr.compare_exchange(ptr::null_mut(), addr, Ordering::SeqCst, Ordering::SeqCst)
27+
match self.addr.compare_exchange(ptr::null_mut(), addr, Ordering::Relaxed, Ordering::Relaxed)
2828
{
2929
Ok(_) => {} // Stored the address
3030
Err(n) if n == addr => {} // Lost a race to store the same address

0 commit comments

Comments
 (0)