我想知道为什么GCC 6.2生成以下汇编输出:
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-12], 0
mfence
mov DWORD PTR [rbp-8], 3
mfence
mov DWORD PTR [rbp-4], 2
mfence
mov eax, 0
pop rbp
ret
来自消息来源:
#include <atomic>
int main(){
std::atomic_thread_fence(std::memory_order_relaxed); // why mfence instead of `nothing`?
std::atomic_thread_fence(std::memory_order_release); // why mfence instead of sfence?
std::atomic_thread_fence(std::memory_order_acquire); // why mfence instead of lfence?
return 0;
}
特别是:
mfence
代替nothing
? mfence
代替sfence
?mfence
代替lfence
?