Answer by David Schwartz for atomic writes and volatile reads
On all platforms that you are likely to use that support C++ and multiple threads, reading from a volatile-qualified, aligned int will be atomic and will read the latest value. However, it is...
View ArticleAnswer by Constantin Baranov for atomic writes and volatile reads
volatile doesn't make read operations atomic. Non-atomic reads concurrent with (atomic) write lead to an undefined behavior. Use atomic read in any form, either std::atomic or intrinsics. Don't use...
View ArticleAnswer by Turn for atomic writes and volatile reads
The volatile keyword only ensures that compiler will not store the variable in a register and instead will load the variable from memory every time it is used. It has nothing to do with the cache or...
View Articleatomic writes and volatile reads
I am designing an multi threaded algorithm in which the requirement is to read the latest value of a shared variable. The writes to the variable are atomic (using compare-and-swap). However, the reads...
View Article