pthread_cond_wait and pthread_cond_signal

Viewed 41

I have a question regarding these 2 functions: When pthread_cond_signal is called before pthread_cond_wait, where exactly does the signal end up? In some kind of queue and then waits until pthread_cond_wait is called ?

I didn't find an explanation regarding this matter.

1 Answers

Condition variable signals are edge events. That means, if you signal a CV when no one is waiting for it, the event is discarded. This is spelled out in the official spec for pthread_cond_signal:

The pthread_cond_broadcast() and pthread_cond_signal() functions shall have no effect if there are no threads currently blocked on cond.

(emphasis mine)

Related