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++


CONCURRENCY.LOCK.TWICE : Locked Twice

Summary

An attempt to acquire a lock when the lock is already held. This can lead to deadlock or other undefined behavior.

Properties

Class Name Locked Twice
Significance reliability
Mnemonic CONCURRENCY.LOCK.TWICE
Categories
MisraC2025 MisraC2025:22.18 Non-recursive mutexes shall not be recursively locked
MisraC2023 MisraC2023:22.18 Non-recursive mutexes shall not be recursively locked
Misra2012 Misra2012:22.18 Non-recursive mutexes shall not be recursively locked
CWE CWE:764 Multiple Locks of a Critical Resource
JPL JPL:9 Place restrictions on the use of semaphores and locks.
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="Locked Twice"

Triggering Functions

Locked Twice warnings can be triggered by the following functions.

Example

#include <pthread.h>

pthread_mutex_t LockA;
pthread_mutex_t LockB;

void LOCK_TWICE(void){
    pthread_mutex_lock(&LockA);
    pthread_mutex_lock(&LockB);
    pthread_mutex_lock(&LockA); /* 'Locked Twice' warning issued here */
                                /* 'Double Lock' warning also issued if enabled */
    /* ... operate on locked data */
    pthread_mutex_unlock(&LockA);
    pthread_mutex_unlock(&LockB);
}

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