To solve this problem with a condition variable , of course
the signaling of the condition variable must be inside the
critical section of the producers.
But there is still a problem, it is a problem with the latency
in real-time systems, if you use only one pthreads mutex
for the producer side and the consumer side , the latency will get much
bigger, because the consumers have to wait for the producers in a FIFO
priority manner, so you have to wrap the producer side inside another
pthreads mutex to lower the latency for the condition variable
case, or you have to use smartly a pthreads semaphore.