Concurrency and parallelism
CP.44
Remember to name your `lock_guard`s and `unique_lock`s
Reason
An unnamed local object is a temporary that immediately goes out of scope.
Example
// global mutexes
mutex m1;
mutex m2;
void f()
{
unique_lock<mutex>(m1); // (A)
lock_guard<mutex> {m2}; // (B)
// do work in critical section ...
}
This looks innocent enough, but it isn't. At (A), m1 is a default-constructed local unique_lock, which shadows the global ::m1 (and does not lock it). At (B) an unnamed temporary lock_guard is constructed and locks ::m2, but immediately goes out of scope and unlocks ::m2 again. For the rest of the function f() neither mutex is locked.
Enforcement
Flag all unnamed lock_guards and unique_locks.