Suppose I have 3 threads, A B and C, a pthread_mutex_t named mutex, and a pthread_cond_t named cond.
Threads B and C are blocking on a call to pthread_cond_wait(&cond, &mutex);
.
Thread A locks the mutex, and calls pthread_cond_signal(&cond);
twice before releasing the mutex.
Is this guaranteed to unblock both threads? More generally, if N threads are already waiting on a condition variable while pthread_cond_signal is called N times, can I assume that at least N waiting threads will be unblocked?
I don't have any specific use case for relying on this (maybe it'd be useful if you queue multiple tasks and want to make sure multiple worker threads wake to handle them?), but I'm trying to determine whether a specific implementation that doesn't make this guarantee can be correct.