Suppose that we have a global std::
container. I wish to write some things to it, and then have many threads read from it. I will not change it after the initial write.
Is there anything preventing the compiler simply from optimizing accesses by storing them in a register or something of the like? Is a keyword like volatile necessary here? What guarantees am I given that operations on the container are always truly committed to memory?
Even with locks and such, I feel such guarantees are somehow necessary, and in a language like C, I might make them via the use of the volatile
keyword.
1