Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C++11 中:如果我增加一个原子变量(std::atomic 上的运算符 ++),新值是否与内存屏障一起存储?还是我必须明确地做一个商店?
您不需要进行显式存储。将使用顺序一致性内存排序。
operator++(int)和operator++()on类型被指定为具有 的效果,最终以默认的内存顺序调用成员函数。atomic<integral>fetch_add(1)memory_order_seq_cst
operator++(int)
operator++()
atomic<
integral
>
fetch_add(1)
memory_order_seq_cst
有关规范,请查看原子类型操作的要求[atomics.types.operations.req] 29.6.5/33