The window is the bug
Nothing is wrong with the read or the write. The bug is the gap between them, which is why the fix is about order and not about code.
Tests hide it
A race often passes on a fast machine and fails on a slow one. Assert a range, or force the overlap with a sleep, before believing a green run.