问题描述
为什么具有以下功能:
#include <atomic>
void store_release(std::atomic<int>& location,int val) {
location.store(val,std::memory_order_release);
}
void store_seq_cst(std::atomic<int>& location,int val) {
location.store(val,std::memory_order_seq_cst);
}
在x86-64(godbolt)上的编译方式有所不同:
store_release(std::atomic<int>&,int):
mov DWORD PTR [rdi],esi
ret
store_seq_cst(std::atomic<int>&,int):
xchg esi,DWORD PTR [rdi]
ret
即使C ++标准声明以std::memory_order_seq_cst
顺序存储操作也会在受影响的内存位置执行释放操作?引用29.3顺序和一致性:
(1.2)memory_order_release,memory_order_acq_rel和memory_order_seq_cst:存储操作对受影响的内存位置执行释放操作
- 如何保证
xchg
指令具有mov
不具有指令? - 为什么seq_cst命令需要这些保证?
- 在这两种情况下,商店的可见性(实际上)会有所不同?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)