Skip to content

Commit

Permalink
two-threads-large benchmark: add third thread for triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed May 1, 2024
1 parent da26e16 commit 0976460
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion benches/two_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(
for i in 0..iters {
push(&mut p, i as u8);
}
let barrier = Arc::new(Barrier::new(2));
let barrier = Arc::new(Barrier::new(3));
let push_thread = {
let barrier = Arc::clone(&barrier);
std::thread::spawn(move || {
Expand All @@ -55,13 +55,25 @@ $(
(start_pushing, stop_pushing)
})
};
let trigger_thread = {
let barrier = Arc::clone(&barrier);
std::thread::spawn(move || {
// Try to force other threads to go to sleep on barrier.
std::thread::yield_now();
std::thread::yield_now();
std::thread::yield_now();
barrier.wait();
// Hopefully, the other two threads now wake up at the same time.
})
};
barrier.wait();
let start_popping = std::time::Instant::now();
for _ in 0..iters {
black_box(pop(&mut c));
}
let stop_popping = std::time::Instant::now();
let (start_pushing, stop_pushing) = push_thread.join().unwrap();
trigger_thread.join().unwrap();
let total = stop_pushing
.max(stop_popping)
.duration_since(start_pushing.min(start_popping));
Expand Down

0 comments on commit 0976460

Please sign in to comment.