@@ -195,9 +195,12 @@ fn wait_absolute_timeout() {
195
195
}
196
196
197
197
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.
198
201
static mut FUTEX : u32 = 0 ;
199
202
200
- let t1 = thread :: spawn ( move || {
203
+ fn waiter ( ) -> bool {
201
204
let mut timeout = libc:: timespec { tv_sec : 0 , tv_nsec : 500_000_000 } ;
202
205
let timeout_size_arg =
203
206
ptr:: without_provenance_mut :: < libc:: c_void > ( mem:: size_of :: < libc:: timespec > ( ) ) ;
@@ -211,23 +214,10 @@ fn wait_wake() {
211
214
) ;
212
215
io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) == libc:: ETIMEDOUT
213
216
}
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) ;
231
221
232
222
// Wake up 1 thread and make sure the other is still waiting
233
223
thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
@@ -247,7 +237,7 @@ fn wait_wake() {
247
237
thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
248
238
let t1_woke_up = t1. join ( ) . unwrap ( ) ;
249
239
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" ) ;
251
241
}
252
242
253
243
fn main ( ) {
0 commit comments