https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115802
--- Comment #8 from Ivan Bodrov <securesneakers at gmail dot com> --- The 2nd example is only intended to show changes in code generation after the fence is moved to the function that is visible, but is not inlined, which is the cause of this issue. The code is not supposed to be correct. This is why the original example has a complete mutex + condvar.