简体   繁体   English

宽松原子操作的内存模型释放/获取模式交互

[英]Memory model release/acquire mode interactions of relaxed atomic operations

The GCC Wiki says this about the memory model synchronization mode Acquire/Release : GCC Wiki 关于内存模型同步模式Acquire/Release 是这样说的

To make matters a bit more complex, the interactions of non-atomic variables are still the same.更复杂的是,非原子变量的相互作用仍然相同。 Any store before an atomic operation must be seen in other threads that synchronize.原子操作之前的任何存储都必须在其他同步线程中看到。 For example:例如:

 -Thread 1- -线程 1-\n y = 20; y = 20;\n x.store (10, memory_order_release); x.store (10, memory_order_release);\n\n -Thread 2- -线程 2-\n if (x.load(memory_order_acquire) == 10)如果(x.load(memory_order_acquire)== 10)\n    assert (y == 20);断言(y == 20);
Since 'y' is not an atomic variable, the store to 'y' happens-before the store to 'x', so the assert cannot fail in this case. 由于“y”不是原子变量,“y”的存储发生在“x”的存储之前,因此在这种情况下断言不会失败。 The optimizers must still limit the operations performed on shared memory variables around atomic operations. 优化器仍然必须限制围绕原子操作对共享内存变量执行的操作。

Now, what if I make 'y' an atomic variable (without imposing happens-before restrictions)?现在,如果我让 'y' 成为一个原子变量(不强加发生之前的限制)怎么办?

 -Thread 1-
 y.store (20, memory_order_relaxed);
 x.store (10, memory_order_release);

 -Thread 2-
 if (x.load(memory_order_acquire) == 10)
    assert (y.load (memory_order_relaxed) == 20);

Can the assert fail?断言会失败吗? Are there fewer requirements for atomic variables than for non-atomic variables?对原子变量的要求是否比对非原子变量的要求少? Or is the Wiki's restriction to non-atomic variables gratuitous and misleading here?或者 Wiki 对非原子变量的限制在这里是无缘无故的和误导性的?

Since 'y' is not an atomic variable, the store to 'y' happens-before the store to 'x'由于“y”不是原子变量,“y”的存储发生在“x”的存储之前

The statement "since y is not an atomic" is incorrect.. The same ordering rules apply to atomic and non-atomic operations.语句“因为y不是原子的”是不正确的。相同的排序规则适用于原子和非原子操作。

Acquire/release barriers guarantee that memory operation A (the store to y ) sequenced before the store/release happens-before memory operation B (the assert ) sequenced after the load/acquire that sees the stored value.获取/释放屏障保证内存操作 A(存储到y )在存储/释放发生之前排序- 在内存操作 B( assert )之前排序在看到存储值的加载/获取之后。 Whether or not operations A and B are atomic is irrelevant.操作 A 和 B 是否是原子的无关紧要。
The assert cannot fire. assert不能触发。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 混合松弛和释放-获取内存指令 - Mixing Relaxed and Release-Acquire Memory Orders memory_order_relaxed 和 Atomic RMW 操作 - memory_order_relaxed and Atomic RMW operations 宽松的原子存储是否在发布前重新排序? (类似于加载/获取) - Are relaxed atomic store reordered themselves before the release? (similar with load /acquire) 可以通过其他获取操作重新排序获取负载吗? cppreference 说只有非原子和放松是由获取排序的 - Can acquire loads reorder with other acquire operations? cppreference says only non-atomic and relaxed are ordered by acquire 在C ++中,获取/释放原子访问与结合围栏的宽松访问之间是否有有效的区别? - In C++, is there any effective difference between a acquire/release atomic access and a relaxed access combined with a fence? 混合对同一个原子变量的放松访问和获取/释放访问如何影响同步? - How does mixing relaxed and acquire/release accesses on the same atomic variable affect synchronises-with? C++ 原子获取/释放操作的实际含义 - C++ atomic acquire / release operations what it actually means 与 memory_order_acquire 和 memory_order_release 的原子交换 - atomic exchange with memory_order_acquire and memory_order_release 如果中间有线程连接,为什么不能使用宽松的原子操作来同步内存? - Why can't you use relaxed atomic operations to synchronize memory, if there is a thread join in between? C ++ 11原子内存排序 - 这是放宽(释放 - 消耗)排序的正确用法吗? - C++11 atomic memory ordering - is this a correct usage of relaxed (release-consume) ordering?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM