When a given thread waits (cnd_wait()
or cnd_timedwait()
) on a condition variable, it can be awakened as a result of a signal operation (cnd_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).
The user is forced to create a predicate-testing - loop around the wait condition to guarantee that each thread executes only if its predicate test is true (recommendation in IEEE Std 1003.1 since the 2001 release [IEEE Std 1003.1-2004]). As a consequence, if a given thread finds the predicate test to be false, it waits again, eventually resulting in a deadlock situation.
Consequently, the The use of cnd_signal()
is safe only if the following conditions are met:
...
The following noncompliant code example consists of a given number of threads (5) that should execute one after another according to the step level assigned to them when they are each thread when it is created (serialized processing). The current_step
variable holds the current step level and is incremented as soon as the respective thread finishes its processing. Finally, another thread is signaled so that the next step can be executed.
...
Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
CON38-C | low | unlikely | medium | P2 | L3 |
Related Guidelines
...
...
...
Bibliography
...