简体   繁体   English

原子操作与易失性原子变量

[英]atomic operation with volatile atomic variable

Why c++ atomic operations has an overloaded version for volatile atomic<T> ? 为什么c ++原子操作对volatile volatile atomic<T>有一个重载版本?

When are we required declare atomic<T> as volatile and what is difference between atomic<T> and volatile atomic<T> ? 我们何时需要将atomic<T>声明为volatile并且atomic<T>volatile atomic<T>之间有什么区别?

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). 它与任何其他类型相同:如果您在内存映射I / O寄存器上执行原子操作,或者需要volatile限定类型的语义(在任何类型中都不相关),则需要对您的原子进行volatile限定原子性或原子操作提供的线程间同步和内存排序的方法。

The standard has this to say about the volatile overloads for atomics ( 29.6.5[atomics.types.operations.req]/3 ) 关于原子的volatile重载,标准有这个说法( 29.6.5[atomics.types.operations.req]/3

[ 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 ] - 尾注]

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM