0

Assuming some pthread_cond_t condvar; properly initialized with pthread_cond_init am I allowed to pthread_cond_broadcast it without any mutex locked and thread blocked with pthread_cond_timedwait on it?

I tend to understand that it is possible (with a well defined "no-op" behavior), but I am not entirely sure. This is how I am understanding

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

My scenario is a weird case where no thread is calling pthread_cond_timedwait on that condvar, but I don't want to special-case and avoid the broadcast. So the only thread using that condvar is the one calling pthread_cond_broadcast (in other words, the cond var is essentially useless in such case, but I try to avoid duplicating code...).

PS. My OS is Linux/Debian with GNU libc, but I prefer a general confirmation about POSIX standard. And Calling pthread_cond_signal without locking mutex is not the same question.

Basile Starynkevitch
  • 32,434
  • 6
  • 84
  • 125

0 Answers0