fix(runtime): panic where a window outlived its region of windows #259
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/253-region-generation"
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?
Closes #253
torb_region_getandtorb_region_set(runtime/task.c) now check the handle's generation and panic with "a window outlived itswindowsregion" instead of readingNULLstorage or writing into the list of a region that reused the slot.torb_region_setalso checks the position itself (torb_panic_index_out_of_bounds), since it is public intorb_natives.h.Hot path decision: the generation is read with one
torb_atomic_load_u32per item, not understate->lock. A lock per item would make every worker of one region contend on the same lock word; the lock buys nothing over an acquire load here, since the check and the copy are not one critical section either way and a stale handle is used aftertorb_region_joinreturned. The join now stores the generation withtorb_atomic_store_u32to pair with it.Tests (
runtime/tests/pool_test.c):region_stale_get_panics,region_stale_set_after_reuse_panics(asserts the slot really is reused and the new region's items are untouched),region_set_out_of_range_panics. Windows tests and conformance cases unchanged.Seed impact: none (runtime only, no syntax, no new native, no signature change).
windowsChecklist (head
3de84184):region_stale_get_panics,region_stale_set_after_reuse_panics(asserts the slot is reused and the new region's items stay untouched) andregion_set_out_of_range_panicsmatch the acceptance criteria; CI green on this head (bootstrap, tier A, tier B, gates).torb_region_livecompares the generation anddata != NULLbefore any use, andtorb_region_setnow bounds-checkspositionitself. The join publishes the new generation with an atomic store that pairs with the acquire load;getstill returns false only for an out-of-range position.Non-blocking:
parallel-windows-count; the PR body gives the reasoning for the atomic load but no timing. Suggestion: add a before/after number in a follow-up comment if it is cheap to get.Approved, merging by rebase.