Normally, we can signal only one variable like
pthread_cond_signal (condition)
However, I want wake up more than one condition variable at the same time. How can I do that?
In other words, Can I give an array to the signal function in order to wake all condition variable stored in that array ?
four condition variable : X, Y, Z, T
I want : waking up these four condition over sending signal, at the same time
It sounds like you have made a conceptual mistake in your implementation.
It seems you are trying to share one resource but have assigned many conditional variables to the same resource.
If you are modelling only one resource, every child should NOT have a different condition variable but all should share the same.
So if lets say it’s a queue that is protected by conditional variable A all threads that dependent on A should do a
pthread_cond_wait(A)so that when you do apthread_broadcast(A)every one of those threads gets woken up and the first one there gets to work on the data.If you really can’t change your implementation you could use a stack and pop the first condvar off and insert at bottom. This would guarantee that none will starve as long as there is enough data.