Problem in WaitableEvent implementation?


We encountered a dual-core issue in a software not using JUCE.
One of my fellow colleagues warned me about a common coding error using the pthread API, and I looked for that in our entire source code tree.

And I found out what he warned me against in the Juce source code.
The problem is in the WaitableEvent class implementation, in juce_Posix_SharedCode.cpp.

According to the pthread_cond_wait documentation here, pthread_cond_wait should be used inside a loop, like this :

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

while (predicate == FALSE) {
(void)pthread_cond_wait(&cond, &mutex);

(void)pthread_mutex_unlock(&mutex); [/code]

This is to

pthread_cond_wait() is recommended to be used in a loop testing the predicate associated with it. This will take care of any spurious wakeups that may occur.[/quote]

I am not an expert in this area, but for my colleague, who is, this is the way things should be done.


ooh… nasty! Ok, I’ve checked in a fix for that. Haven’t thoroughly tested it yet, but think it’ll be ok…


wow! this may be the source of the race condition bug I’m encountering on my dual core processor on my PC too.
gonna download svn to test :slight_smile: