The real advantage of a scoped lock is that it promises to release the mutex, no matter how the scope is exited. If this LOCKED macro is used and an exception is thrown from within the block, that mutex now stays locked. > The only gotcha is, there is some overhead involved in this approach. The class instance takes up some space on the stack (several bytes) for every lock acquisition. Not so fast. A decent compiler…
(1) avoids best practice (RAII) using...
(2) a flawed rationale (ignoring the existence of compiler optimizations)...
(3) without measurement to demonstrate the supposed flaw in the best practice (which would have surfaced the flawed rationale)...
(4) and therefore implements a micro-optimization with no actual win...
(5) and introduces a bug in the process (it's not exception safe).