Skip to content

Commit 5581e33

Browse files
committed
Add test for FUTEX_*_BITSET.
1 parent 53ed500 commit 5581e33

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,59 @@ fn wait_wake() {
160160
assert!((200..1000).contains(&start.elapsed().as_millis()));
161161
}
162162

163+
fn wait_wake_bitset() {
164+
let start = Instant::now();
165+
166+
static FUTEX: i32 = 0;
167+
168+
thread::spawn(move || {
169+
thread::sleep(Duration::from_millis(200));
170+
unsafe {
171+
assert_eq!(libc::syscall(
172+
libc::SYS_futex,
173+
&FUTEX as *const i32,
174+
libc::FUTEX_WAKE_BITSET,
175+
10, // Wake up at most 10 threads.
176+
0,
177+
0,
178+
0b1001, // bitset
179+
), 0); // Didn't match any thread.
180+
}
181+
thread::sleep(Duration::from_millis(200));
182+
unsafe {
183+
assert_eq!(libc::syscall(
184+
libc::SYS_futex,
185+
&FUTEX as *const i32,
186+
libc::FUTEX_WAKE_BITSET,
187+
10, // Wake up at most 10 threads.
188+
0,
189+
0,
190+
0b0110, // bitset
191+
), 1); // Woken up one thread.
192+
}
193+
});
194+
195+
unsafe {
196+
assert_eq!(libc::syscall(
197+
libc::SYS_futex,
198+
&FUTEX as *const i32,
199+
libc::FUTEX_WAIT_BITSET,
200+
0,
201+
ptr::null::<libc::timespec>(),
202+
0,
203+
0b0100, // bitset
204+
), 0);
205+
}
206+
207+
assert!((400..1000).contains(&start.elapsed().as_millis()));
208+
}
209+
163210
fn main() {
164211
wake_nobody();
165212
wake_dangling();
166213
wait_wrong_val();
167214
wait_timeout();
168215
wait_absolute_timeout();
169216
wait_wake();
217+
wait_wake_bitset();
170218
}

0 commit comments

Comments
 (0)