std::scoped_lock constructed with no mutex arguments
ID |
c.correctness.scoped_lock_without_arguments |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Concurrency |
Language |
C / C++ |
Description
This std::scoped_lock is constructed with no mutex arguments, so it locks nothing: the guard exists but provides no mutual exclusion, defeating the purpose of taking it. Pass the mutex or mutexes it should hold for its scope: std::scoped_lock guard(mutex1, mutex2, …).
Rationale
This std::scoped_lock is constructed with no mutex arguments, so it locks nothing: the guard exists but provides no mutual exclusion, defeating the purpose of taking it. Pass the mutex or mutexes it should hold for its scope: std::scoped_lock guard(mutex1, mutex2, …).
The following code illustrates the pattern detected by this rule:
void locks_nothing()
{
// FLAGGED: std::scoped_lock constructed with no mutex arguments
std::scoped_lock guard;
}