if you're writing code for your own use, and don't care about portability
or security, go ahead and use volatile as a synchronization primitive.
But if the code is going to be accepted into an open source project
that gets wide use, volatile is a bad idea. But don't take my word
for it; here's what kernel.org, cert.org, and an intel researcher say about it:
"Volatile considered harmful",
"The use of volatile is likely to be seen as a bug and will bring
additional scrutiny to the code."
"CERT Secure Coding Standards, recommendation POS03: Do not use
volatile as a synchronization primitive"
"A variable declared as volatile is not cached in a register, leading
to this confusion that it can be used safely as a synchronization
primitive. When declared volatile, the compiler does not re-order the
sequence of reads and writes to that memory location. However, the
compiler might re-order these reads and writes with those to other
memory locations. This might result in non-atomic operations on the
synchronization variable resulting in errors."
"Ad Hoc Synchronization Considered Harmful",
"Ad hoc synchronizations are error-prone. Significant percentages
(22-67%) of these ad hoc synchronizations introduced bugs or severe
Volatile is a 1980's solution to a 2000's problem, and it just doesn't
cut the mustard anymore.
Linux-audio-dev mailing list