Doesn't using C++ RAII eliminate some of that? Or you use raw pointers often?
The one for RAII looks like this:
{
mutex_guard(some_mutex);
foo();
}
What does this do? It locks some_mutex, then immediately unlocks it, then calls foo(). {
mutex_guard guard(some_mutex);
foo();
}The answer to the code review question is obvious. I didn't see the error even though I was told what happens.
Anyway, the first example creates a temporary object which doesn't lock anything since it will be destroyed right away because it's an rvalue (not sure why would anyone do that for locking, unless not knowingly). The second example creates a proper guard which lives until the end of the scope.