I am developing a multi-threaded library that helps the transformation of messages between threads in different processes using shared memory.
I am using the pthreads condition facility in order to synchronize access to the shared memory slots through which the messages are passed.
My test program got stuck. Obviously, most of the threads were stuck in the call to pthread_cond_wait(), waiting for a shared memory slot to become vacant.
However, what stuck the program was one of the threads who got stuck in
the call to pthread_cond_signal().
Obviously, since he got stuck there, none of the other threads awoke and consequently, the entire test program got stuck.
I will also mention that I am using the PTHREAD_PROCESS_SHARED attribute for the condition variable.
I am running on Ubuntu Linux 10.04.
Has anybody encountered a situation where pthread_cond_signal() is stuck?
Any idea about the reasons for this situation?
Thank you for responding.
Producing the code for the forum would not be possible, if only because it is a part of a complicated project. I don't currently have a short working example.
My "waiter" code looks like:
pthread_mutex_lock(pWaiter->getMutex());
while (!pWaiter->getFlag())
pthread_cond_wait(pWaiter->getCond(), pWaiter->getMutex());
pthread_mutex_unlock(pWaiter->getMutex());