about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorConnor Tsui <connor.tsui20@gmail.com>2024-11-08 18:13:18 -0500
committerConnor Tsui <connor.tsui20@gmail.com>2024-11-16 12:31:14 -0500
commit84fd95cbedf1e1c1826e378ffc4d1a3d335deff4 (patch)
tree5f64286c72d130d9ca619bfc326066f8c596024d /library/std/src/sys
parent3d191b50d2b5a4b17eda2f8cccaa5088ef56b8af (diff)
downloadrust-84fd95cbedf1e1c1826e378ffc4d1a3d335deff4.tar.gz
rust-84fd95cbedf1e1c1826e378ffc4d1a3d335deff4.zip
fix memory ordering bug + bad test
This commit fixes a memory ordering bug in the futex implementation
(`Relaxed` -> `Release` on `downgrade`).

This commit also removes a badly written test that deadlocked and
replaces it with a more reasonable test based on an already-tested
`downgrade` test from the parking-lot crate.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/sync/rwlock/futex.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/std/src/sys/sync/rwlock/futex.rs b/library/std/src/sys/sync/rwlock/futex.rs
index e0f4a91e073..961819cae8d 100644
--- a/library/std/src/sys/sync/rwlock/futex.rs
+++ b/library/std/src/sys/sync/rwlock/futex.rs
@@ -195,7 +195,7 @@ impl RwLock {
     #[inline]
     pub unsafe fn downgrade(&self) {
         // Removes all write bits and adds a single read bit.
-        let state = self.state.fetch_add(DOWNGRADE, Relaxed);
+        let state = self.state.fetch_add(DOWNGRADE, Release);
         debug_assert!(is_write_locked(state), "RwLock must be write locked to call `downgrade`");
 
         if has_readers_waiting(state) {