Re:Memory-mapped IO registers in Zig. (2021)
by foldr on Tuesday April 23, 2024 @08:46AM
(#40131346)
If two pieces of code are accessing irq_flags concurrently then the load and store operations from each may be interleaved, giving incorrect results.
[ Parent
| on HN ]
Re:Memory-mapped IO registers in Zig. (2021)
by bsaul on Wednesday April 24, 2024 @03:26AM
(#40141639)
Ok but what makes it specific to volatile ? This pb happens with all memory.
Are volatile variables used for atomic memory access semantic ?
Re:Memory-mapped IO registers in Zig. (2021)
by foldr on Wednesday April 24, 2024 @04:19AM
(#40141906)
I guess the point was that in the case of a non-volatile variable, the variable would typically be in a register and the compiler would typically compile foo |= CONSTANT into a single instruction (though there is no guarantee of any of this). But if the variable is volatile then the compiler would have to load it from memory into a register, perform the bitwise operation, and then store it again. If irq_flags represents a memory mapped register then you'd need to force the second option.