3 ms·
I could understand this argument against the RAII-style destructor unlock, but this lambda approach seems actually better in the visibility sense since the mute
by pavlov 4y ago
I could understand this argument against the RAII-style destructor unlock, but this lambda approach seems actually better in the visibility sense since the mutex access is a separately indented block.
- amadvance 4y agoIt's obviously subjective, but it looks like as any other indented block. Named "lock" and "unlock" operations are more explicit to me. Another potential disadvantage, is that you lose the possibility to control the unlock order, when you have multiple nested locks.
- gpderetta 4y agoAn indented scope (that starts with a scoped_lock or some appropriately named function) is more explicit than lock/unlock calls interspersed in the code. std::scoped_lock allows locking multiple locks.
- snozolli 4y agothis lambda approach seems actually better in the visibility sense since the mutex access is a separately indented block. When I'm writing multithreaded code, the first line of any block containing a RAII lock is the lock. Any subsection of code that needs another lock gets its own block.