You should only call pthread_cond_wait if the variable is already in the "wrong" state. Since he always waits, there is always overhead associated with transferring the current stream and switching.
When a thread is unplanned, it is unplanned. It should not use any resources, but, of course, the OS can be theoretically implemented poorly. It is allowed to re-acquire mutexes and even return before the signal (therefore, you must double-check the condition), but the OS will be implemented so that this does not affect performance much if this happens at all. This does not occur spontaneously, but rather in response to another, possibly unrelated signal.
30,000 mutexes should not be a problem, but some operating systems may have a problem with 30,000 sleeping threads.
source share