放宽原子规则的(轻微)区别是什么? [英] What is the (slight) difference on the relaxing atomic rules?

查看:54
本文介绍了放宽原子规则的(轻微)区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在看到Herb Sutters出色后的"rel ="nofollow">对话.我对 Relaxed Atomics 示例感到困惑.

After seeing Herb Sutters excellent talk about "atomic weapons" I got a bit confused about the Relaxed Atomics examples.

我认为 C ++内存模型中的 atomic (SC-DRF =数据竞速免费顺序一致)在负载/阅读.

I took with me that an atomic in the C++ Memory Model (SC-DRF = Sequentially Consistent for Data Race Free) does an "acquire" on a load/read.

我知道对于负载[和商店],默认值为 std :: memory_order_seq_cst ,因此两者相同:

I understand that for a load [and a store] the default is std::memory_order_seq_cst and therefore the two are the same:

myatomic.load();                          // (1)
myatomic.load(std::memory_order_seq_cst); // (2)

到目前为止,到目前为止,还没有涉及到轻松原子学"(在听完演讲后,我将永远不会使用轻松的原子学.曾经,但是,当有人问我时,我可能不得不解释一下...).

So far so good, no Relaxed Atomics involved (and after hearing the talk I will never to use the relaxed ones. Ever. Promise. But when someone asks me, I might have to explain...).

但是当我使用它时,为什么它是宽松的"语义?

But why is it the "relaxed" semantics when I use

myatomic.load(std::memory_order_acquire);   // (3)

由于加载正在获取并且未释放,所以为什么这与(1)(2)?在这里 实际上放松了什么?

Since load is acquiring and not releasing, why is this different from (1) and (2)? What actually is relaxed here?

我唯一能想到的就是我误解了 load 意味着 acquire .并且,如果这是真的,并且默认的 seq_cst 表示两者,那不是意味着一个完整的栅栏吗?没有什么东西可以传递该指令,也不能传递下去?我必须误会了那部分.

The only thing I can think of is that I misunderstood that load means acquire. And if that is true, and the default seq_cst means both, doesn't that mean a full fence -- nothing can pass up that instruction, nor down? I have to have misunderstood that part.

[并且对称地表示 store release ].

[and symmetrically for store and release].

推荐答案

调用 myatomic.load(std :: memory_order_acquire); 一个松弛原子"可能会有些混乱.加载,因为有一个 std :: memory_order_relaxed .有些人将任何比 seq_cst 弱的顺序描述为松弛".

It can be a bit confusing to call myatomic.load(std::memory_order_acquire); a "relaxed atomic" load, since there is a std::memory_order_relaxed. Some people describe any order weaker than seq_cst as "relaxed".

您应该正确地注意到,顺序一致的负载是获取负载,但是它还有一个附加要求:对于所有seq_cst操作,顺序一致的负载也是总全局顺序的一部分.

You're right to note that sequentially-consistent load is an acquire load, but it has an additional requirement: sequentially-consistent load is also a part of the total global order for all seq_cst operations.

当您处理多个原子变量时,它会起作用:两个原子的单独修改顺序对于不同的线程可能以不同的相对顺序出现,除非强加了顺序一致性.

It comes into play when you're dealing with more than one atomic variable: individual modification orders of two atomics may appear in different relative order to different threads, unless sequential consistency is imposed.

这篇关于放宽原子规则的(轻微)区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆