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.STARVE.BLOCKING : Blocking in Critical Section

Summary

A blocking function is called while a lock is held.

Properties

Class Name Blocking in Critical Section
Significance reliability
Mnemonic CONCURRENCY.STARVE.BLOCKING
Categories
CWE CWE:662 Improper Synchronization
CERT-C CERT-C:CON05-C Do not perform operations that can block while holding a lock
  CERT-C:POS52-C Do not perform operations that can block while holding a POSIX lock
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Blocking in Critical Section"

Triggered When

The code calls a blocking function while holding one or more locks, where:

a blocking function Any function treated as a blocking function by CodeSonar:
  • any library function that is recognized as a blocking function because CodeSonar ships with a library model that identifies it as such, and
  • any function for which you have added a library model identifying it as a blocking function.
a thread holds lock L if it has acquired L with one of the following, but not yet released it.
  • Any function treated as a lock acquisition function by CodeSonar:
    • any library function that is recognized as a lock acquisition function because CodeSonar ships with a library model that identifies it as such, and
    • any function for which you have added a library model identifying it as a lock acquisition function.
  • Any function specified with the LOCK_FUNCTIONS configuration file parameter,

Example

#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>

void concurrency_starve_blocking(pthread_mutex_t lock){
    sleep(2);                              /* ok: No lock held at this time */
    if( pthread_mutex_lock(&lock) != 0 ){
        abort();
    }
    sleep(3);               /* 'Blocking in Critical Section' warning issued here
                             * - a lock is held while the thread blocks.
                             */
    if( pthread_mutex_unlock(&lock) != 0 ) abort();
    sleep(4);                              /* ok: No lock held at this time */
}

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/.