mirror of
https://github.com/HeyPuter/gex.git
synced 2026-11-13 18:34:21 -10:00
A locked access across two 8-byte words ran under the global split lock and stored its value with a plain store. The lock keeps such accesses atomic against each other, but a store of the value's bytes undid any aligned atomic another thread made in between to a field overlapping them. That field may be native code's own, such as kernel32's InterlockedIncrement on the counter beside. Both copies now commit through one compare-exchange per word: cgen's gex_locked_misaligned in the header, and tier-1's emit_misaligned_atomic. - The first word is written when it is unchanged since the read; if it changed, the access starts again. - The second word retries with whatever the bytes around the value now hold. - If the value's own bytes in the second word changed, the access puts the first word's bytes back while they still hold what it wrote, and starts again. Every split access therefore reads and writes the value atomically against aligned atomics on either word as well. wow64/splitlock gains a 32-bit "overlap" case. - One thread makes 1000000 locked increments, in its own code, of a counter at 6 mod 8. - The other thread calls InterlockedIncrement, the whole time, on the aligned counter at 8, which overlaps the first counter's upper half. - The case passes only when both counts are exact. - Natively, the old code lost 20310 of the other thread's 327824 rounds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_853378b774d645b4ac78b16d9af91a31