I'm working with POSIX and I've 3 threads.
Please note all the threads below uses the same mutex lock.
Thread 1 is waiting using pthread_cond_wait for a condition to be met(the wait is within a while loop, so its not an unconditional wait too). Thread 2 is going to issue a pthread_cond_broadcast when condition is met. Thread 3 uses the mutex for locking but doesn't wait on the conditional variable.
So, thread 1 is waiting for signal/broadcast and thread 3 is waiting for the mutex lock(this thread is just waiting to acquire mutex lock). Now if thread 2 sends a broadcast, somehow thread 3 is acquiring the mutex instead of thread 1. Why would this happen? I'm using debian 8.3 using glibc2.19. Shouldn't the broadcast wake up the thread which was waiting on the conditional variable?