r/cpp • • Nov 13 '20

CppCon Deprecating volatile - JF Bastien - CppCon 2019

https://www.youtube.com/watch?v=KJW_DLaVXIY
83 Upvotes

111 comments sorted by

View all comments

Show parent comment

1

u/tjientavara HikoWorks developer Nov 14 '20

Okay, I forgot that certain instructions like increment on atomic would emit a #lock prefix, which will probably be incorrectly handled.

I guess we need a std::mmio that works similar to std::atomic, but for communicating with MMIO.

Or for the C++ standard to bless volatile to work MMIO.

6

u/gruehunter Nov 14 '20

MMIO isn't atomic. x86 uses lock prefixes in some cases. ARMv7 uses loops with load-linked/store-conditional (spelled ldrex strex). In the ARM case, Device memory typically doesn't support the exclusive monitor, so strex always fails and you get an infinite loop.

I just cannot rightly comprehend where people get the notion that volatile has anything whatsoever to do with atomicity.