Skip to content

Commit

Permalink
futex text: avoid spurious non-atomic reads
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 24, 2023
1 parent 2ab963f commit d7206eb
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/pass-dep/concurrency/linux-futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@compile-flags: -Zmiri-disable-isolation

use std::mem::MaybeUninit;
use std::ptr;
use std::ptr::{self, addr_of};
use std::sync::atomic::AtomicI32;
use std::sync::atomic::Ordering;
use std::thread;
Expand All @@ -13,15 +13,15 @@ fn wake_nobody() {

// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
unsafe {
assert_eq!(libc::syscall(libc::SYS_futex, &futex as *const i32, libc::FUTEX_WAKE, 1), 0);
assert_eq!(libc::syscall(libc::SYS_futex, addr_of!(futex), libc::FUTEX_WAKE, 1), 0);
}

// Same, but without omitting the unused arguments.
unsafe {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&futex as *const i32,
addr_of!(futex),
libc::FUTEX_WAKE,
1,
ptr::null::<libc::timespec>(),
Expand Down Expand Up @@ -52,7 +52,7 @@ fn wait_wrong_val() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&futex as *const i32,
addr_of!(futex),
libc::FUTEX_WAIT,
456,
ptr::null::<libc::timespec>(),
Expand All @@ -73,7 +73,7 @@ fn wait_timeout() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&futex as *const i32,
addr_of!(futex),
libc::FUTEX_WAIT,
123,
&libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 },
Expand Down Expand Up @@ -110,7 +110,7 @@ fn wait_absolute_timeout() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&futex as *const i32,
addr_of!(futex),
libc::FUTEX_WAIT_BITSET,
123,
&timeout,
Expand All @@ -136,7 +136,7 @@ fn wait_wake() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&FUTEX as *const i32,
addr_of!(FUTEX),
libc::FUTEX_WAKE,
10, // Wake up at most 10 threads.
),
Expand All @@ -149,7 +149,7 @@ fn wait_wake() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&FUTEX as *const i32,
addr_of!(FUTEX),
libc::FUTEX_WAIT,
0,
ptr::null::<libc::timespec>(),
Expand All @@ -173,7 +173,7 @@ fn wait_wake_bitset() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&FUTEX as *const i32,
addr_of!(FUTEX),
libc::FUTEX_WAKE_BITSET,
10, // Wake up at most 10 threads.
ptr::null::<libc::timespec>(),
Expand All @@ -188,7 +188,7 @@ fn wait_wake_bitset() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&FUTEX as *const i32,
addr_of!(FUTEX),
libc::FUTEX_WAKE_BITSET,
10, // Wake up at most 10 threads.
ptr::null::<libc::timespec>(),
Expand All @@ -204,7 +204,7 @@ fn wait_wake_bitset() {
assert_eq!(
libc::syscall(
libc::SYS_futex,
&FUTEX as *const i32,
addr_of!(FUTEX),
libc::FUTEX_WAIT_BITSET,
0,
ptr::null::<libc::timespec>(),
Expand Down Expand Up @@ -244,7 +244,7 @@ fn concurrent_wait_wake() {
unsafe {
let ret = libc::syscall(
libc::SYS_futex,
&FUTEX as *const AtomicI32,
addr_of!(FUTEX),
libc::FUTEX_WAIT,
HELD,
ptr::null::<libc::timespec>(),
Expand All @@ -267,7 +267,7 @@ fn concurrent_wait_wake() {
FUTEX.store(FREE, Ordering::Relaxed);
unsafe {
DATA = 1;
libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1);
libc::syscall(libc::SYS_futex, addr_of!(FUTEX), libc::FUTEX_WAKE, 1);
}

t.join().unwrap();
Expand Down

0 comments on commit d7206eb

Please sign in to comment.