Re: Simple, easy multithreaded circular buffer library for Linux?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 17, 2008 at 2:06 PM, Joern Nettingsmeier
<nettings@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> excuse my chiming in here, i'm not really much of a c programmer... but
> how can this
>  -  rb->read_ptr += n1;
>  -  rb->read_ptr &= rb->size_mask;
>  +  rb->read_ptr = (rb->read_ptr + n1) & rb->size_mask;
> fix anything?
>
> iiuc, both versions are equivalent. a context switch could happen just
> as well after the parenthesis has been computed..!?
> putting stuff on one line doesn't make it atomic. maybe you are now
> getting another compiler optimization that helps to hide the bug?
>

They are not equivalent.  The first version modifies rb->readptr
twice; the second version modifies once.  I can't say with any
certainty that that fixes the problem, but it makes me feel better
(and happens to pass this test).

There's no chance that a compiler optimization is hiding the bug,
because we haven't turned on optimization.   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).

Now THAT's interesting...
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux