Skip to content

Commit d7206eb

Browse files
committed
futex text: avoid spurious non-atomic reads
1 parent 2ab963f commit d7206eb

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

tests/pass-dep/concurrency/linux-futex.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@compile-flags: -Zmiri-disable-isolation
33

44
use std::mem::MaybeUninit;
5-
use std::ptr;
5+
use std::ptr::{self, addr_of};
66
use std::sync::atomic::AtomicI32;
77
use std::sync::atomic::Ordering;
88
use std::thread;
@@ -13,15 +13,15 @@ fn wake_nobody() {
1313

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

1919
// Same, but without omitting the unused arguments.
2020
unsafe {
2121
assert_eq!(
2222
libc::syscall(
2323
libc::SYS_futex,
24-
&futex as *const i32,
24+
addr_of!(futex),
2525
libc::FUTEX_WAKE,
2626
1,
2727
ptr::null::<libc::timespec>(),
@@ -52,7 +52,7 @@ fn wait_wrong_val() {
5252
assert_eq!(
5353
libc::syscall(
5454
libc::SYS_futex,
55-
&futex as *const i32,
55+
addr_of!(futex),
5656
libc::FUTEX_WAIT,
5757
456,
5858
ptr::null::<libc::timespec>(),
@@ -73,7 +73,7 @@ fn wait_timeout() {
7373
assert_eq!(
7474
libc::syscall(
7575
libc::SYS_futex,
76-
&futex as *const i32,
76+
addr_of!(futex),
7777
libc::FUTEX_WAIT,
7878
123,
7979
&libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 },
@@ -110,7 +110,7 @@ fn wait_absolute_timeout() {
110110
assert_eq!(
111111
libc::syscall(
112112
libc::SYS_futex,
113-
&futex as *const i32,
113+
addr_of!(futex),
114114
libc::FUTEX_WAIT_BITSET,
115115
123,
116116
&timeout,
@@ -136,7 +136,7 @@ fn wait_wake() {
136136
assert_eq!(
137137
libc::syscall(
138138
libc::SYS_futex,
139-
&FUTEX as *const i32,
139+
addr_of!(FUTEX),
140140
libc::FUTEX_WAKE,
141141
10, // Wake up at most 10 threads.
142142
),
@@ -149,7 +149,7 @@ fn wait_wake() {
149149
assert_eq!(
150150
libc::syscall(
151151
libc::SYS_futex,
152-
&FUTEX as *const i32,
152+
addr_of!(FUTEX),
153153
libc::FUTEX_WAIT,
154154
0,
155155
ptr::null::<libc::timespec>(),
@@ -173,7 +173,7 @@ fn wait_wake_bitset() {
173173
assert_eq!(
174174
libc::syscall(
175175
libc::SYS_futex,
176-
&FUTEX as *const i32,
176+
addr_of!(FUTEX),
177177
libc::FUTEX_WAKE_BITSET,
178178
10, // Wake up at most 10 threads.
179179
ptr::null::<libc::timespec>(),
@@ -188,7 +188,7 @@ fn wait_wake_bitset() {
188188
assert_eq!(
189189
libc::syscall(
190190
libc::SYS_futex,
191-
&FUTEX as *const i32,
191+
addr_of!(FUTEX),
192192
libc::FUTEX_WAKE_BITSET,
193193
10, // Wake up at most 10 threads.
194194
ptr::null::<libc::timespec>(),
@@ -204,7 +204,7 @@ fn wait_wake_bitset() {
204204
assert_eq!(
205205
libc::syscall(
206206
libc::SYS_futex,
207-
&FUTEX as *const i32,
207+
addr_of!(FUTEX),
208208
libc::FUTEX_WAIT_BITSET,
209209
0,
210210
ptr::null::<libc::timespec>(),
@@ -244,7 +244,7 @@ fn concurrent_wait_wake() {
244244
unsafe {
245245
let ret = libc::syscall(
246246
libc::SYS_futex,
247-
&FUTEX as *const AtomicI32,
247+
addr_of!(FUTEX),
248248
libc::FUTEX_WAIT,
249249
HELD,
250250
ptr::null::<libc::timespec>(),
@@ -267,7 +267,7 @@ fn concurrent_wait_wake() {
267267
FUTEX.store(FREE, Ordering::Relaxed);
268268
unsafe {
269269
DATA = 1;
270-
libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1);
270+
libc::syscall(libc::SYS_futex, addr_of!(FUTEX), libc::FUTEX_WAKE, 1);
271271
}
272272

273273
t.join().unwrap();

0 commit comments

Comments
 (0)