> We know that the C++ keyword volatile is used to prevent a value from being optimized in a way that would allow the compiler to keep it in a processor register rather than fetching it from its original memory location each time.
Actually, we don't know that. The meaning of volatile is rather subtle
It does mean the compiler needs to treat loading and storing the value as a side effect - actually write a load instruction every time it's loaded in the source code. It's as if *X was a call to get_X() the compiler can't optimize around. However the next sentence which says you can use it for thread synchronization is wrong.
einpoklum · · focus · HN ↗
Actually, we don't know that. The meaning of volatile is rather subtle
someonebaggy · · focus · HN ↗