修改订单不是总订单是什么意思?
What does it mean that the modification order is not a total order?
Each atomic object has its own associated modification order, which is a total order of modifications made to that object. If, from some thread's point of view, modification A of some atomic M happens-before modification B of the same atomic M, then in the modification order of M, A occurs before B.
Note that although each atomic object has its own modification order, it is not a total order; different threads may observe modifications to different atomic objects in different orders.
这两个大胆的说法是不是自相矛盾?我在 https://en.cppreference.com/w/c/language/atomic 上找到了它们,想知道现在到底发生了什么 - 是不是全部订单?现在究竟什么是有保证的,什么不是?
这确实是 cppreference 的一个错误选择。重要的一句话其实就是最后一句话:不同的线程可能会以不同的顺序观察到对不同原子对象的修改
因此,如果原子对象 1 具有完全有序的修改序列 A B C,而原子对象 2 具有完全有序的序列 D E F,则所有线程将在 C 之前看到 A,在 F 之前看到 D,但线程可能不同意 A 是否出现在D之前。因此,所有修改的集合{A B D C E F}
没有总顺序。
但是所有同意 B 先于 E 的线程也会同意 A 先于 F。部分顺序仍然提供一些保证。
Each atomic object has its own associated modification order, which is a total order of modifications made to that object. If, from some thread's point of view, modification A of some atomic M happens-before modification B of the same atomic M, then in the modification order of M, A occurs before B.
Note that although each atomic object has its own modification order, it is not a total order; different threads may observe modifications to different atomic objects in different orders.
这两个大胆的说法是不是自相矛盾?我在 https://en.cppreference.com/w/c/language/atomic 上找到了它们,想知道现在到底发生了什么 - 是不是全部订单?现在究竟什么是有保证的,什么不是?
这确实是 cppreference 的一个错误选择。重要的一句话其实就是最后一句话:不同的线程可能会以不同的顺序观察到对不同原子对象的修改
因此,如果原子对象 1 具有完全有序的修改序列 A B C,而原子对象 2 具有完全有序的序列 D E F,则所有线程将在 C 之前看到 A,在 F 之前看到 D,但线程可能不同意 A 是否出现在D之前。因此,所有修改的集合{A B D C E F}
没有总顺序。
但是所有同意 B 先于 E 的线程也会同意 A 先于 F。部分顺序仍然提供一些保证。