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 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With