When we hand code to the compiler, it only sees named memory locations and the need to move data between registers and memory. This means it cannot understand or handle the mapping between the abstract states (e.g., hardware status or concurrency information) expressed by the programming language’s symbolic system and the actual physical memory.

As a result, a variable or code snippet that is crucial at the abstract level may appear redundant to the compiler. Such code is therefore prone to being altered or removed by the compiler’s optimizations. This is precisely why we mark that code as volatile — to inform the compiler of its special status (, or side effects).

Thus, to the compiler, the code itself is in fact volatile.


<
Previous Post
Different Locks
>
Blog Archive
Archive of all previous blog posts