gpt4 book ai didi

c++11 原子排序 : extended total order memory_order_seq_cst for locks

转载 作者:太空狗 更新时间:2023-10-29 21:48:22 26 4
gpt4 key购买 nike

来自 c++11 29.3-p3:

There shall be a single total order S on all memory_order_seq_cst operations, consistent with the "happens before" order and modification orders for all affected locations, such that each memory_order_seq_cst operation B that loads a value from an atomic object M observes either one of the following values:

-- the result of the last modification A of M that precedes B in S, if it exists, or

-- if A exists, the result of some modification of M in the visible sequence of side effects with respect to B that is not memory_order_seq_cst and that does not happen before A, or

-- if A does not exist, the result of some modification of M in the visible sequence of side effects with respect to B that is not memory_order_seq_cst.

[ Note: Although it is not explicitly required that S include locks, it can always be extended to an order that does include lock and unlock operations, since the ordering between those is already included in the "happens before" ordering. --end note ]

在最后一个注释中,“始终”是什么意思?我可以理解任何特定的实现都可以设计为支持这样的扩展 S。但是在一些不是为此设计的通用实现中,我看不到 S 可以使用所描述的属性进行扩展。

这是否意味着这里也满足相同可见性属性的扩展顺序?

我已经把这个问题发给了 comp.std.c++ 但没有得到答案。 http://groups.google.com/group/comp.std.c++/browse_frm/thread/5242fa70d0594d1b#

最佳答案

What does it mean by "always"?

Always表示总存在一个订单S+lseq_cst ops U lock ops这与 happens-before 一致和 S .

这是为什么

事实 1:S是与HB一致的总序.

事实 2:锁定操作在 HB 中排序部分顺序,因为它们是获取/释放操作。

事实 3:HB 中没有循环.

引理 1:S' = S union HB 中没有环.

证明:如果 S' 中有环, 它们的形式为 Aop1 <S Aop2 <HB Aop1 ,因为任何两个原子操作在 S 中都是可比较的happens-before 是传递性的。这将与事实 1 相矛盾。QED

结论:因为对于每个偏序(=没有循环)存在其对全序的扩展(参见拓扑排序),所以有一个全序扩展S'。 .所以你只需从中选择原子和锁定操作并得到 S+l .

But in some general implementation that wasn't designed for it, I don't see that S can be extended so.

这样的实现不会满足 mem_order_seq_cst要求。

关于c++11 原子排序 : extended total order memory_order_seq_cst for locks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10869322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com