From e35530055483e994da68b34a5e35c601d278d551 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 23 Oct 2018 05:25:09 -0400 Subject: [PATCH] use callbacks in parallel test --- tests/parallel/setup.rs | 14 ++++++++++++++ tests/parallel/true_parallel.rs | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/parallel/setup.rs b/tests/parallel/setup.rs index be89f720..81d9f1be 100644 --- a/tests/parallel/setup.rs +++ b/tests/parallel/setup.rs @@ -56,6 +56,9 @@ pub(crate) struct KnobsStruct { /// threads to ensure we reach various weird states. pub(crate) signal: Arc, + /// When this database is about to block, send a signal. + pub(crate) signal_on_will_block: Cell, + /// Invocations of `sum` will signal this stage on entry. pub(crate) sum_signal_on_entry: Cell, @@ -114,6 +117,17 @@ impl Database for ParDatabaseImpl { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime } + + fn salsa_event(&self, event_fn: impl Fn() -> salsa::Event) { + let event = event_fn(); + match event.kind { + salsa::EventKind::WillBlockOn { .. } => { + self.signal(self.knobs().signal_on_will_block.get()); + } + + _ => {} + } + } } impl ParallelDatabase for ParDatabaseImpl { diff --git a/tests/parallel/true_parallel.rs b/tests/parallel/true_parallel.rs index e8073dac..278e2e00 100644 --- a/tests/parallel/true_parallel.rs +++ b/tests/parallel/true_parallel.rs @@ -66,13 +66,15 @@ fn true_parallel_same_keys() { } }); - // Thread 2 will sync barrier *just* before calling `sum`. Doesn't - // guarantee the race we want but makes it highly likely. + // Thread 2 will wait until Thread 1 has entered sum and then -- + // once it has set tself to block -- signal Thread 1 to + // continue. This way, we test out the mechanism of one thread + // blocking on another. let thread2 = std::thread::spawn({ let db = db.fork(); move || { db.knobs().signal.wait_for(1); - db.knobs().signal.signal(2); + db.knobs().signal_on_will_block.set(2); db.sum("abc") } });