C and C++ Binaries


CONCURRENCY.BADFUNC.CNDSIGNAL : Use of Condition Variable Signal

要旨

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.

プロパティ

クラス名 Use of Condition Variable Signal
日本語クラス名 Use of Condition Variable Signal
クラス分類 信頼性 (reliability)
ニーモニック CONCURRENCY.BADFUNC.CNDSIGNAL
カテゴリー
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
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Use of Condition Variable Signal"

#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);
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。