Skip to content

Commit 0976460

Browse files
committed
two-threads-large benchmark: add third thread for triggering
1 parent da26e16 commit 0976460

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

benches/two_threads.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $(
4141
for i in 0..iters {
4242
push(&mut p, i as u8);
4343
}
44-
let barrier = Arc::new(Barrier::new(2));
44+
let barrier = Arc::new(Barrier::new(3));
4545
let push_thread = {
4646
let barrier = Arc::clone(&barrier);
4747
std::thread::spawn(move || {
@@ -55,13 +55,25 @@ $(
5555
(start_pushing, stop_pushing)
5656
})
5757
};
58+
let trigger_thread = {
59+
let barrier = Arc::clone(&barrier);
60+
std::thread::spawn(move || {
61+
// Try to force other threads to go to sleep on barrier.
62+
std::thread::yield_now();
63+
std::thread::yield_now();
64+
std::thread::yield_now();
65+
barrier.wait();
66+
// Hopefully, the other two threads now wake up at the same time.
67+
})
68+
};
5869
barrier.wait();
5970
let start_popping = std::time::Instant::now();
6071
for _ in 0..iters {
6172
black_box(pop(&mut c));
6273
}
6374
let stop_popping = std::time::Instant::now();
6475
let (start_pushing, stop_pushing) = push_thread.join().unwrap();
76+
trigger_thread.join().unwrap();
6577
let total = stop_pushing
6678
.max(stop_popping)
6779
.duration_since(start_pushing.min(start_popping));

0 commit comments

Comments
 (0)