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

Fons Adriaensen fons at linuxaudio.org
Mon Jul 11 20:53:37 UTC 2011


On Mon, Jul 11, 2011 at 09:59:25PM +0300, Dan Muresan wrote:
 
> and the NPTL code in glibc *seems* to perform a memory barrier only on
> sem_post().

Wouldn't that seem quite natural ? Semas provide one-way communication.
It's the sem_post() that means there is an event to be seen by some
other thread. So it has to make sure that any data related to it is
visible to the receiver. The receiver taking the event (returning
from sem_wait()), or checking for it (calling sem_wait()), is not
meant to be an event for the other side. You need a second sema if
events have to go both ways.

For a ringbuffer you need two anyway if the buffer is longer than
one item, and you want to signal both of 'not empty' and 'not full' 
in the appropriate direction.

Ciao,

-- 
FA




More information about the Linux-audio-dev mailing list