1 use crate::setup
::{ParDatabase, ParDatabaseImpl}
;
2 use crate::signal
::Signal
;
3 use salsa
::{Database, ParallelDatabase}
;
6 /// Add test where a call to `sum` is cancelled by a simultaneous
7 /// write. Check that we recompute the result in next revision, even
8 /// though none of the inputs have changed.
10 fn in_par_get_set_cancellation() {
11 let mut db
= ParDatabaseImpl
::default();
15 let signal
= Arc
::new(Signal
::default());
17 let thread1
= std
::thread
::spawn({
18 let db
= db
.snapshot();
19 let signal
= signal
.clone();
21 // Check that cancellation flag is not yet set, because
22 // `set` cannot have been called yet.
23 assert
!(!db
.salsa_runtime().is_current_revision_canceled());
25 // Signal other thread to proceed.
28 // Wait for other thread to signal cancellation
29 while !db
.salsa_runtime().is_current_revision_canceled() {
30 std
::thread
::yield_now();
33 // Since we have not yet released revision lock, we should
35 let v
= db
.input('a'
);
37 // Since this is a snapshotted database, we are in a consistent
38 // revision, so this must yield the same value.
39 let w
= db
.input('a'
);
45 let thread2
= std
::thread
::spawn({
46 let signal
= signal
.clone();
48 // Wait until thread 1 has asserted that they are not cancelled
49 // before we invoke `set.`
52 // This will block until thread1 drops the revision lock.
59 let (a
, b
) = thread1
.join().unwrap();
63 let c
= thread2
.join().unwrap();