Skip to content

Commit

Permalink
two-threads-small benchmark: remove barrier
Browse files Browse the repository at this point in the history
... because it can busy-wait instead.
  • Loading branch information
mgeier committed May 1, 2024
1 parent cc44e51 commit da26e16
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions benches/two_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ $(
let (create, push, pop) = help_with_type_inference($create, $push, $pop);
// Queue is very short in order to force a lot of contention between threads.
let (mut p, mut c) = create(2);
let barrier = Arc::new(Barrier::new(2));
let push_thread = {
let barrier = Arc::clone(&barrier);
std::thread::spawn(move || {
barrier.wait();
// The timing starts once both threads are ready.
let start = std::time::Instant::now();
for i in 0..iters {
while !push(&mut p, i as u8) {
Expand All @@ -127,7 +125,7 @@ $(
start
})
};
barrier.wait();
// While the second thread is still starting up, this thread will busy-wait.
for i in 0..iters {
loop {
if let Some(x) = pop(&mut c) {
Expand All @@ -137,6 +135,7 @@ $(
std::hint::spin_loop();
}
}
// The timing stops once all items have been received.
let stop = std::time::Instant::now();
let start = push_thread.join().unwrap();
stop.duration_since(start)
Expand Down

0 comments on commit da26e16

Please sign in to comment.