问题描述
N3243 1.10.21说
这是否意味着任何 seq_cst 都写在原子对象对于其他按 seq_cst 顺序读取原子对象的线程是立即可见的?
否,C ++标准中没有任何东西可以保证立即可见。
原子写入应该在合理的时间内对其他线程可见。
所保证的是单个总订单 memory_order_seq_cst
操作。因此,未看到写入值的读取必须以总顺序早于写入的顺序发生。由于此总订单包含所有变量和所有 memory_order_seq_cst
操作,因此,如果线程之间完全没有通信,然后必须很快就能看到写入内容。
N3243 1.10.21 says
Does this mean that any seq_cst writes on an atomic object are immediately visible to other threads which read the atomic object with seq_cst ordering ?
No, there is nothing in the C++ standard that guarantees immediate visibility.
Atomic writes should become visible to other threads within a "reasonable" period of time, but they do not have to be immediate, and there is no precise definition of "reasonable".
What is guaranteed is that there is a single total order of memory_order_seq_cst
operations. A read that does not see the value written must therefore occur earlier in that total order than the write. Since this total order encompasses all variables and all memory_order_seq_cst
operations, if there is any communication between the threads at all, then writes must become visible pretty quickly.
这篇关于seq_cst排序是否保证立即可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!