Further clarification on volatile

volatile is fine and must be used when there are side effects such as accessing MMIO or buffers that change with DMA.

See the volatile documentation

The flag is so simple case that might work with volatile and normally works with relaxed (.monotonic) atomic because instructions order seems to not matter in this simple case.

Quoting Linus Torvalds:

If the memory barriers are right, then the “volatile” doesn’t matter.
And if the memory barriers aren’t right, then “volatile” doesn’t help.

See: Why the “volatile” type class should not be used

2 Likes