[英]c++11 atomic ordering: extended total order memory_order_seq_cst for locks
from c++11 29.3-p3: 来自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:
在所有memory_order_seq_cst操作上应该存在单个总订单S,与所有受影响位置的“发生之前”订单和修改订单一致,使得从原子对象M加载值的每个memory_order_seq_cst操作B观察到以下任一个中的任何一个值:
-- the result of the last modification A of M that precedes B in S, if it exists, or
- 在S中位于B之前的M的最后修改A的结果,如果存在,或者
-- 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
- 如果A存在,则对于B的副作用的可见序列中的M的某些修改的结果不是在memory_order_seq_cst之前且在A之前不发生,或者
-- 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.
- 如果A不存在,则对于不是memory_order_seq_cst的B的副作用的可见序列中的M的某些修改的结果。
[ 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.
[注意:虽然没有明确要求S包含锁,但它总是可以扩展到包含锁定和解锁操作的顺序,因为它们之间的顺序已经包含在“之前发生”排序中。 --end note ]
- 后注]
In the last note, what does it mean by "always"? 在最后一个注释中,“始终”是什么意思? I can understand that any certain implementation can be designed to support such an extended S. But in some general implementation that wasn't designed for it, I don't see that S can be extended with the described properties.
我可以理解,任何特定的实现都可以设计为支持这样的扩展S.但是在一些不是为它设计的一般实现中,我没有看到S可以用所描述的属性进行扩展。
Does it mean an extended order that also satisfies the same visibility properties here? 这是否意味着扩展订单也满足相同的可见性属性?
I had sent this question to comp.std.c++ but got no answers there. 我把这个问题发给了comp.std.c ++,但那里没有答案。 http://groups.google.com/group/comp.std.c++/browse_frm/thread/5242fa70d0594d1b#
http://groups.google.com/group/comp.std.c++/browse_frm/thread/5242fa70d0594d1b#
What does it mean by "always"?
“永远”是什么意思?
Always means that there exists a total order S+l
on seq_cst ops U lock ops
that is consistent with happens-before
and S
. 始终意味着在
seq_cst ops U lock ops
上存在与order happens-before
和S
一致的总顺序S+l
。
Fact 1: S
is a total order consistent with HB
. 事实1:
S
是与HB
一致的总订单。
Fact 2: Lock operations are ordered in the HB
partial order, because they are acquire/release operations. 事实2:锁定操作按
HB
部分顺序排序,因为它们是获取/释放操作。
Fact 3: There are no cycles in HB
. 事实3:
HB
中没有循环。
Lemma 1: There are no cycles in S' = S union HB
. 引理1:
S' = S union HB
中没有循环。
Proof: If there were any cycles in S'
, they would be in the form Aop1 <S Aop2 <HB Aop1
, because any two atomic operations are comparable in S
and happens-before is transitive. 证明:如果
S'
有任何循环,它们将采用Aop1 <S Aop2 <HB Aop1
,因为任何两个原子操作在S
都是可比较的并且发生之前是传递的。 That would contradict with Fact 1. QED 这与事实1. QED相矛盾
Conclusion: Because for each partial order (= without cycles) there exists its extension to total order (cf. topological sorting), there is a total order extending S'
. 结论:因为对于每个部分顺序(=没有循环),存在其对总顺序的扩展(参见拓扑排序),存在扩展
S'
的总顺序。 So you just pick atomics and lock operations from it and get S+l
. 所以你只需从中选择原子并锁定操作并得到
S+l
。
But in some general implementation that wasn't designed for it, I don't see that S can be extended so.
但是在一些不是为它设计的一般实现中,我没有看到S可以扩展。
Such an implementation would not satisfy mem_order_seq_cst
requirements. 这样的实现不满足
mem_order_seq_cst
要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.