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:
Meta Vens 2026-11-27 21:00:44 +01:00
commit 17ae70ac07

View file

@ -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})");