C and C++ Binaries


CONCURRENCY.BADFUNC.CNDSIGNAL : Use of Condition Variable Signal

Summary

A use of a function such as pthread_cond_signal() to unblock a thread that is blocked on a condition variable. This can lead to concurrency problems if multiple threads are sharing a condition variable.

If you get a warning of this class, check to make sure that all threads are using separate, unique condition variables. If so (and your organization has not forbidden the use of these functions), you can ignore the warning, for example by setting its Priority to Suppressed.

See also Use of Condition Variable Wait.

Properties

Class Name Use of Condition Variable Signal
Significance reliability
Mnemonic CONCURRENCY.BADFUNC.CNDSIGNAL
Categories
CWE CWE:676 Use of Potentially Dangerous Function
CERT-C CERT-C:CON38-C Preserve thread safety and liveness when using condition variables
CERT-CPP CERT-CPP:CON55-CPP Preserve thread safety and liveness when using condition variables
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Use of Condition Variable Signal"

Example

#include <pthread.h>

pthread_mutex_t lock;
pthread_cond_t cond;
unsigned int test;

void make_test_false()
{
    pthread_mutex_lock(&lock);
    while (test == 0)
        pthread_cond_wait(&cond, &lock);                     /* 'Use of Condition Variable Wait' warning issued here */
    test = 0;
    pthread_mutex_unlock(&lock);
}

void make_test_true()
{
    pthread_mutex_lock(&lock);
    if (test == 0)
        pthread_cond_signal(&cond);      /* 'Use of Condition Variable Signal' warning issued here */
    test = 1;
    pthread_mutex_unlock(&lock);
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.