Zach
Zach

Reputation: 537

pthread_cond_signal on non-waiting cond_t variable

As a part of my program, i use the command "pthread_cond_signal(cv)".
I want to use this line to "free" the waiting cv (but i don't know if this current cv is really waiting now).
Is it OK to do so also if this cv (a pthread_cond_t variable) is not waiting? (I mean, pthread_cond_wait was not called upon it before)?
What would be the behavior in this case?
Thanks a lot.

Upvotes: 1

Views: 204

Answers (1)

Mat
Mat

Reputation: 206669

From the documentation of pthread_cond_signal:

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

So nothing happens if nothing is waiting on the condition.

Upvotes: 3

Related Questions