cultcache-rs: gate race test spawns its two writers directly
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cb2eb9269d
commit
17ae70ac07
1 changed files with 12 additions and 13 deletions
|
|
@ -1086,21 +1086,20 @@ fn two_caches_racing_one_value_through_the_gate_leave_one_holder() {
|
|||
let value = format!("V{round}");
|
||||
let gate = std::sync::Barrier::new(2);
|
||||
let (won_left, won_right) = std::thread::scope(|scope| {
|
||||
let run = |cache: &mut CultCache, key: String| {
|
||||
let (gate, value) = (&gate, &value);
|
||||
scope.spawn(move || {
|
||||
gate.wait();
|
||||
match cache.put(&key, &unique(value)) {
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
conflict_of(&error);
|
||||
false
|
||||
}
|
||||
let (gate, value) = (&gate, &value);
|
||||
let attempt = move |cache: &mut CultCache, key: String| {
|
||||
gate.wait();
|
||||
match cache.put(&key, &unique(value)) {
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
conflict_of(&error);
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
let l = run(&mut left, format!("l{round}"));
|
||||
let r = run(&mut right, format!("r{round}"));
|
||||
let (left, right) = (&mut left, &mut right);
|
||||
let l = scope.spawn(move || attempt(left, format!("l{round}")));
|
||||
let r = scope.spawn(move || attempt(right, format!("r{round}")));
|
||||
(l.join().unwrap(), r.join().unwrap())
|
||||
});
|
||||
assert!(won_left ^ won_right, "{round}: exactly one writer lands (left {won_left}, right {won_right})");
|
||||
|
|
|
|||
Loading…
Reference in a new issue