The C++ standard has little to say about volatile. It was originally intended for the very specific application of writing device drivers that communicate with hardware via memory-mapped I/O.
그렇다면 결국 volatile 키워드가 하는 일은 간단히 말해, 최적화를 하지 않고, 접근해야 할 메모리에 순서대로 제대로 접근하게 하는 일일 것이다.
- To make that work, compilers must follow these rules:
- A read or write to a volatile variable must not be eliminated by the compiler. Reads and writes to volatile variables must not be reordered by the compiler, relative to one-another.
그렇다면 결국 volatile 키워드가 하는 일은 간단히 말해, 최적화를 하지 않고, 접근해야 할 메모리에 순서대로 제대로 접근하게 하는 일일 것이다.