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

From: Chris Cannam <cannam@email-addr-hidden-day-breakfast.com>
Date: Tue Jul 12 2011 - 22:45:53 EEST

On 12 July 2011 13:44, Dan Muresan <danmbox@email-addr-hidden> wrote:
> I wonder if
>
> {
> pthread_mutex_t dummy = PTHREAD_MUTEX_INITIALIZER;
> pthread_mutex_lock(&dummy);
> pthread_mutex_unlock(&dummy);
> }
>
> doesn't provide a portable full memory barrier.

According to http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
the answer must surely be yes -- pthread_mutex_lock provides a memory
barrier and the only (explicit) exception is for recursive mutexes
already held by the caller.

> Oh, and you probably need a barrier in the consummer too

Yes, before updating the read index (I said read index earlier when I
meant write index).

Thinking it over and going back over some references and earlier
threads here (e.g. much earlier ones from Olivier et al) it does seem
that this should be enough. This particular situation isn't so
complicated after all. I think the more I read earlier during this
thread (and reading around) generally about memory ordering, the more
I was beginning to feel as if the entire subject was a source of only
trouble.

Chris
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Wed Jul 13 00:15:01 2011

This archive was generated by hypermail 2.1.8 : Wed Jul 13 2011 - 00:15:01 EEST