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

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

 



Fons Adriaensen wrote:
> On Fri, Oct 17, 2008 at 08:06:55PM +0200, Joern Nettingsmeier 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?
> 
> The idea is that it is very unlikely that the compiler
> would store the intermediate result in rb->read_ptr,
> and so this value is updated only once.

i see. but what about the other scenario:
thread A reads read_ptr.
thread B runs and increments it.
thread A increases the old (wrong) read_ptr value by one and writes a
wrong value.

isn't that a problem here?

-- 
jörn nettingsmeier

home://germany/45128 essen/lortzingstr. 11/
http://spunk.dnsalias.org
phone://+49/201/491621

Kurt is up in Heaven now.
_______________________________________________
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