If I have 2 mutexes locked, and I have a condvar for each one, is there an easy way to wait for either condvar to fire? I want to leave holding both locks again, and with (at least) one of the condvars having been signaled.
no easy way that i can see, i would just create a third condvar and mutex, because you are really waiting for a different condition.
No. You end up with a race condition. Imagine both signals are sent before pthread_cond_wait
returns. One gets thrown away, and they're indistinguishable.
Another way to think, as Luke says, is that there are two different conditions happening. When you get the signal, you double-check the condition. If there are two conditions, there is clearly a race condition if the other condition may change while you are checking it.
The solution is to have two different threads. If those threads would need to be exclusive, use another lock to synchronize them.
Redesign? Without knowing much about what you want to do: Try using one mutex and multiple condvars. If you want to wait for either condvar make a third condvar that is fired whenever the first one or second one is fired (or something like this).