简体   繁体   English

c ++ 11原子排序:锁的扩展总命令memory_order_seq_cst

[英]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-beforeS一致的总顺序S+l

Why is that 这是为什么

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.

相关问题 标准C ++ 11是否保证memory_order_seq_cst阻止StoreLoad在原子周围重新排序非原子? - Does standard C++11 guarantee that memory_order_seq_cst prevents StoreLoad reordering of non-atomic around an atomic? C++11 memory_model_relaxed 和 memory_order_seq_cst 关系 - C++11 memory_model_relaxed and memory_order_seq_cst relation output 10 与 memory_order_seq_cst - output 10 with memory_order_seq_cst atomic_thread_fence(memory_order_seq_cst) 是否具有完整内存屏障的语义? - Does atomic_thread_fence(memory_order_seq_cst) have the semantics of a full memory barrier? 在这种情况下,带有 memory_order_seq_cst 的原子读操作读取哪个值? - Which value does atomic read operation with memory_order_seq_cst read in this situation? 与 `std::mutex` 同步是否比与 `std::atomic(memory_order_seq_cst)` 同步慢? - Is synchronizing with `std::mutex` slower than with `std::atomic(memory_order_seq_cst)`? memory_order_seq_cst 如何与非原子操作同步? - How does memory_order_seq_cst synchronize with non-atomic operations? 标记为 std::memory_order_seq_cst 的单个原子操作是否会在任何地方触发顺序一致性? - Does a single atomic operation marked as std::memory_order_seq_cst trigger sequential consistency everywhere? 为什么“memory_order_relaxed”在我的系统中被视为“memory_order_seq_cst”[C++] - Why “memory_order_relaxed” treat as “memory_order_seq_cst” in my system [C++] memory_order_seq_cst 栅栏什么时候有用? - When is a memory_order_seq_cst fence useful?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM