Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When a given thread waits (pthread_cond_wait() or pthread_cond_timedwait()) on a condition variable, it can be awakened as result of a signal operation (pthread_cond_signal()). However, if multiple threads are waiting on the same condition variable, any of those threads can be picked up by the scheduler to be awakened (assuming that all threads have the same priority level and also that they have only one mutex associated with the condition variable). See guideline CON37POS53-C. Do not use more than one mutex for concurrent waiting operations on a condition variable.

...

Therefore, this noncompliant code example violates the [BB. Definitions#livenessDefinitions[liveness property.

Compliant Solution (Using pthread_cond_broadcast())

...

The CERT Oracle Secure Coding Standard for Java: THI04-J. Notify all waiting threads rather than a single thread

Bibliography

[Open Group] pthread_cond_signal() pthread_cond_broadcast()

...