简体   繁体   中英

atomic operation with volatile atomic variable

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

When are we required declare atomic<T> as volatile and what is difference between atomic<T> and 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).

The standard has this to say about the volatile overloads for atomics ( 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 ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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