On Oct 9, 4:27 am, Joshua Maurice <joshuamaur...@gmail.com> wrote:
The compiler could optimize away a load, and keep a variable
in a register, like in a busy waiting loop on a flag. I
would not rely upon "eventually". For sufficiently complex
code, such that it must reload it from memory, you are
correct. However, "sufficiently complex" is entirely
dependent on the machine on which its running. I don't feel
comfortable looking at a piece of code and saying "Yeah,
that's sufficiently complex to require spilling the register
holding that value."
What I also go back and forth on is: should the target
variable of an atomic operation be volatile? Every atomic API
I've ever seen uses volatile. For example:
bool atomic_flag_test_and_set(volatile atomic_flag*);
So, is it enough that the formal argument is volatile, or must
the actual argument be volatile also?