[LAD] a *simple* ring buffer, comments pls?

Dan Kegel dank at kegel.com
Sun Jul 10 22:34:39 UTC 2011


Guys,
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",
http://www.kernel.org/doc/Documentation/volatile-considered-harmful.txt
"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"
https://www.securecoding.cert.org/confluence/display/seccode/POS03-C.+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",
www.xiongww.com/papers/osdi10-xiong.pdf
"Ad hoc synchronizations are error-prone. Significant percentages
(22-67%) of these ad hoc synchronizations introduced bugs or severe
performance issues."

Volatile is a 1980's solution to a 2000's problem, and it just doesn't
cut the mustard anymore.
- Dan



More information about the Linux-audio-dev mailing list