use callbacks in parallel test

This commit is contained in:
Niko Matsakis 2018-10-23 05:25:09 -04:00
parent 59ab0bd7a2
commit e355300554
2 changed files with 19 additions and 3 deletions

View file

@ -56,6 +56,9 @@ pub(crate) struct KnobsStruct {
/// threads to ensure we reach various weird states. /// threads to ensure we reach various weird states.
pub(crate) signal: Arc<Signal>, pub(crate) signal: Arc<Signal>,
/// When this database is about to block, send a signal.
pub(crate) signal_on_will_block: Cell<usize>,
/// Invocations of `sum` will signal this stage on entry. /// Invocations of `sum` will signal this stage on entry.
pub(crate) sum_signal_on_entry: Cell<usize>, pub(crate) sum_signal_on_entry: Cell<usize>,
@ -114,6 +117,17 @@ impl Database for ParDatabaseImpl {
fn salsa_runtime(&self) -> &salsa::Runtime<ParDatabaseImpl> { fn salsa_runtime(&self) -> &salsa::Runtime<ParDatabaseImpl> {
&self.runtime &self.runtime
} }
fn salsa_event(&self, event_fn: impl Fn() -> salsa::Event<Self>) {
let event = event_fn();
match event.kind {
salsa::EventKind::WillBlockOn { .. } => {
self.signal(self.knobs().signal_on_will_block.get());
}
_ => {}
}
}
} }
impl ParallelDatabase for ParDatabaseImpl { impl ParallelDatabase for ParDatabaseImpl {

View file

@ -66,13 +66,15 @@ fn true_parallel_same_keys() {
} }
}); });
// Thread 2 will sync barrier *just* before calling `sum`. Doesn't // Thread 2 will wait until Thread 1 has entered sum and then --
// guarantee the race we want but makes it highly likely. // 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 thread2 = std::thread::spawn({
let db = db.fork(); let db = db.fork();
move || { move || {
db.knobs().signal.wait_for(1); db.knobs().signal.wait_for(1);
db.knobs().signal.signal(2); db.knobs().signal_on_will_block.set(2);
db.sum("abc") db.sum("abc")
} }
}); });