The `unsync_load` is used because, at that point, two things are guaranteed: - The only thread that mutates the field is the `unsync_load` caller - All other threads will only read from that field.
Because of this, we can just do a "plain old" access of the field w/o the atomic overhead.
As for whether or not it should be in `std`, I don't know. It probably could, but it doesn't have to. It's a pretty "advanced" access strategy.
x = load-relaxed(a)
...
f(x)
cannot be turned into x0 = load-relaxed(a)
...
x1 = load-relaxed(a)
f(x1)
while this would be possible with normal memory access.so under register pressure the compiler would be required to spill something onto the stack instead of just reloading `x` from the original location.
Can't you get some values "out of thin air" (partial updates of some bits.) Or some intermediate values?
(For example, can the compiler decide to use this memory location to store some unrelated temporary result, as it knows it will erase it soon with a final value and that no other threads is supposed to access this)
Although in this case, I guess this is probably fine since the non-atomic read can't race with a write.