Skip to content

Commit

Permalink
Fixing multithreaded test
Browse files Browse the repository at this point in the history
At some point I broke this test without realizing it. If you were lucky,
the test passed immediatly. If you were unlucky, integer underflow meant
the test would never finish.

Thankfully after fixing the logic issue with tracking outstanding work,
the test still passes -- thanks in part to this being tested in other
environments pretty thoroughly at this point.
  • Loading branch information
ecton committed Aug 2, 2024
1 parent 924a65f commit 0b3cdc3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn round_robin() {
.0
.send(Command::Enqueue(Root::new(WorkUnit::default(), &guard)))
.expect("worker disconnected early");
outstanding.push_one();
}
drop(guard);

Expand Down Expand Up @@ -76,7 +77,7 @@ fn thread_worker(
if queue.items.is_empty() {
next_thread
.send(Command::Work)
.expect("next thread disconnted");
.expect("next thread disconnected");
} else {
let work = match queue.items[0].as_root(&guard) {
Some(work) => {
Expand Down Expand Up @@ -119,6 +120,10 @@ impl OutstandingWork {
fn complete_one(&self) {
self.0.fetch_sub(1, Ordering::Acquire);
}

fn push_one(&self) {
self.0.fetch_add(1, Ordering::Acquire);
}
}

struct WorkUnit {
Expand Down

0 comments on commit 0b3cdc3

Please sign in to comment.