[LAU] Simple, easy multithreaded circular buffer library for Linux?

Fons Adriaensen fons at kokkinizita.net
Fri Oct 17 16:09:24 EDT 2008


On Fri, Oct 17, 2008 at 02:33:00PM -0400, Paul Coccoli wrote:

> There's no chance that a compiler optimization is hiding the bug,
> because we haven't turned on optimization.

But there is nothing that stops the compiler from writing 
read_ptr any number of times it wants unless you make that
variable volatile.

>  HOWEVER, if you go back
> to the original version and REMOVE the volatile qualifiers, then
> re-compile with -O2, NOW a compiler optimization is hiding the bug
> (and the test passes)!  The rb->read_ptr is presumably cached in a
> register and hence only modified once (giving the same affect as the
> patch).

Indeed. The original version really invited the problem,
by *forcing* the compiler to write read_ptr twice.

Ciao,

-- 
FA

Laboratorio di Acustica ed Elettroacustica
Parma, Italia

Lascia la spina, cogli la rosa.




More information about the Linux-audio-user mailing list