Skip to content

Commit b5ddca3

Browse files
use xor instead of NAND, bedause xor is the correct way
1 parent 406ab4c commit b5ddca3

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,12 @@ fn wait_absolute_timeout() {
195195
}
196196

197197
fn wait_wake() {
198+
// we create 2 threads that wait on a futex with a 500ms timeout.
199+
// The main thread wakes up 1 thread waiting on this futex and after 100ms
200+
// checks that only 1 thread woke up and the other timed out.
198201
static mut FUTEX: u32 = 0;
199202

200-
let t1 = thread::spawn(move || {
203+
fn waiter() -> bool {
201204
let mut timeout = libc::timespec { tv_sec: 0, tv_nsec: 500_000_000 };
202205
let timeout_size_arg =
203206
ptr::without_provenance_mut::<libc::c_void>(mem::size_of::<libc::timespec>());
@@ -211,23 +214,10 @@ fn wait_wake() {
211214
);
212215
io::Error::last_os_error().raw_os_error().unwrap() == libc::ETIMEDOUT
213216
}
214-
});
215-
let t2 = thread::spawn(move || {
216-
let mut timeout = libc::timespec { tv_sec: 0, tv_nsec: 500_000_000 };
217-
let timeout_size_arg =
218-
ptr::without_provenance_mut::<libc::c_void>(mem::size_of::<libc::timespec>());
219-
unsafe {
220-
libc::_umtx_op(
221-
addr_of!(FUTEX) as *mut _,
222-
libc::UMTX_OP_WAIT_UINT_PRIVATE,
223-
0, // FUTEX is 0
224-
// make sure the threads still exit
225-
timeout_size_arg,
226-
&mut timeout as *mut _ as _,
227-
);
228-
io::Error::last_os_error().raw_os_error().unwrap() == libc::ETIMEDOUT
229-
}
230-
});
217+
}
218+
219+
let t1 = thread::spawn(waiter);
220+
let t2 = thread::spawn(waiter);
231221

232222
// Wake up 1 thread and make sure the other is still waiting
233223
thread::sleep(Duration::from_millis(200));
@@ -247,7 +237,7 @@ fn wait_wake() {
247237
thread::sleep(Duration::from_millis(100));
248238
let t1_woke_up = t1.join().unwrap();
249239
let t2_woke_up = t2.join().unwrap();
250-
assert!(!(t1_woke_up && t2_woke_up), "Expected only 1 thread to wake up");
240+
assert!(t1_woke_up ^ t2_woke_up, "Expected 1 thread to wake up");
251241
}
252242

253243
fn main() {

0 commit comments

Comments
 (0)