Compiler memory barriers has the effect among other things to force the compiler to make sure all stack variables that are cached in registers are written t
Since you are willing to work with gcc extensions you could use the extensions for atomic instructions for that feature:
__sync_bool_compare_and_swap(&myvar, 0, 0)
would set the value of the variable to 0
if it is already 0
:) and in addition imply a full sequential consistency on that memory location.