mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
use callbacks in parallel test
This commit is contained in:
parent
59ab0bd7a2
commit
e355300554
2 changed files with 19 additions and 3 deletions
|
@ -56,6 +56,9 @@ pub(crate) struct KnobsStruct {
|
|||
/// threads to ensure we reach various weird states.
|
||||
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.
|
||||
pub(crate) sum_signal_on_entry: Cell<usize>,
|
||||
|
||||
|
@ -114,6 +117,17 @@ impl Database for ParDatabaseImpl {
|
|||
fn salsa_runtime(&self) -> &salsa::Runtime<ParDatabaseImpl> {
|
||||
&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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue