易失性原子变量的原子操作 [英] atomic operation with volatile atomic variable

查看:78
本文介绍了易失性原子变量的原子操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么c ++原子操作对volatile atomic<T>具有重载版本?

Why c++ atomic operations has an overloaded version for volatile atomic<T>?

我们什么时候需要将atomic<T>声明为volatile,并且atomic<T>volatile atomic<T>有什么区别?

When are we required declare atomic<T> as volatile and what is difference between atomic<T> and volatile atomic<T>?

推荐答案

与其他任何类型相同:如果您要在内存映射的I/O寄存器上执行原子操作,则需要对原子进行volatile限定否则需要使用volatile限定类型的语义(这与原子性或原子操作提供的线程间同步和内存排序没有任何关系).

It's the same as with any other type: you need to volatile-qualify your atomic if you're performing atomic operations on a memory-mapped I/O register or otherwise require the semantics of volatile-qualified types (which are not related in any way to atomicity or to the inter-thread synchronization and memory ordering provided by atomic operations).

标准中有关于原子(29.6.5[atomics.types.operations.req]/3)的volatile重载的说法

The standard has this to say about the volatile overloads for atomics (29.6.5[atomics.types.operations.req]/3)

[注:许多操作都经过volatile限定. 作为设备寄存器的易失性"语义没有改变 在标准中.此资格意味着在将这些操作应用于 易挥发的物体.这并不意味着对非易失性对象的操作会变得易失.因此,挥发性 在某些情况下,可以合并对非易失性对象进行的合格操作. —尾注]

[ Note: Many operations are volatile-qualified. The "volatile as device register" semantics have not changed in the standard. This qualification means that volatility is preserved when applying these operations to volatile objects. It does not mean that operations on non-volatile objects become volatile. Thus, volatile qualified operations on non-volatile objects may be merged under some conditions. —end note ]

这篇关于易失性原子变量的原子操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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