Why does GCC use mov/mfence instead of xchg to implement C11's atomic_store?
问题 In C++ and Beyond 2012: Herb Sutter - atomic<> Weapons, 2 of 2 Herb Sutter argues (around 0:38:20) that one should use xchg , not mov / mfence to implement atomic_store on x86. He also seems to suggest that this particular instruction sequence is what everyone agreed one. However, GCC uses the latter. Why does GCC use this particular implementation? 回答1: Quite simply, the mov and mfence method is faster as it does not trigger a redundant memory read like the xchg which will take time. The x86