C and C++ Binaries


CONCURRENCY.BADFUNC.CNDWAIT : Use of Condition Variable Wait

要旨

A use of a function such as pthread_cond_wait() to wait 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 Signal.

プロパティ

クラス名 Use of Condition Variable Wait
日本語クラス名 Use of Condition Variable Wait
クラス分類 信頼性 (reliability)
ニーモニック CONCURRENCY.BADFUNC.CNDWAIT
カテゴリー
CERT-C CERT-C:CON36-C Wrap functions that can spuriously wake up in a loop
CERT-CPP CERT-CPP:CON54-CPP Wrap functions that can spuriously wake up in a loop
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Use of Condition Variable Wait"

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

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

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