std::recursive_mutex used
ID |
c.correctness.recursive_mutex |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Concurrency |
Language |
C / C++ |
Description
This declares a std::recursive_mutex. Needing the same thread to re-enter a lock it already holds is usually a sign that the locking design does not track ownership clearly, and code built around it tends to accumulate deadlocks as it grows. Restructure so each lock is acquired at most once per call chain, and use a plain std::mutex.
Rationale
This declares a std::recursive_mutex. Needing the same thread to re-enter a lock it already holds is usually a sign that the locking design does not track ownership clearly, and code built around it tends to accumulate deadlocks as it grows. Restructure so each lock is acquired at most once per call chain, and use a plain std::mutex.
The following code illustrates the pattern detected by this rule:
// FLAGGED: std::recursive_mutex used
std::recursive_mutex global_lock;
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.