JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++
Binaries


CONCURRENCY.BADFUNC.CNDWAIT : Use of Condition Variable Wait

Summary

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.

Properties

Class Name Use of Condition Variable Wait
Significance reliability
Mnemonic CONCURRENCY.BADFUNC.CNDWAIT
Categories
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
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 Wait"

Example

#include <pthread.h>

pthread_mutex_t lock;
pthread_cond_t cond;
unsigned int test;

void make_test_false(void)
{
    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(void)
{
    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.

 

To report problems with this documentation, please visit https://support.codesecure.com/.