On 12 July 2011 13:44, Dan Muresan <danmbox(a)gmail.com> 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…
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