Watch: range_lock's first read does not undo a set_range_lock that came in meanwhile #2650
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2650"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by boraswim on 2026-11-29T15:33:05Z.
Part of #2420 (the switch race noted there from the review of #2439).
What it changes
victory_gpu::watch::range_lock()cachesVICTORY_RANGE_LOCKinRANGE_LOCK(0 not asked yet, 1 off, 2 on). On its first call it didload→ read the env var →store. Aset_range_lock(true)from another thread that lands between thatloadandstorewas overwritten with the env var's answer, which is off by default.In a run this is harmless, because the variable decides the switch once. But
set_range_lockexists for tests of other crates (#[doc(hidden)], used byvictory-hle's xmem tests), and there any thread's firstrange_lock()could switch it back off mid-test.The first read now installs its answer with
compare_exchange(0, ..). If something was set in the meantime, it returns that value instead. There is no change when nothing races: the same single env read, the same cached value.How it was tested
cargo test -p victory-gpu --lib -- watch::62 passed, 0 failed.cargo clippy -p victory-gpu --lib -- -D warningsreports nothing inwatch.rs(main's other clippy errors are #2048's). There is no deterministic test for the interleaving without a hook inside the first read, so none was added.cargo testpassed for the crates it touches: yes (victory-gpuwatch tests)Checked for overlap
range_lockorRANGE_LOCK.