6 ms·
> because it makes you pay less for the same benefit. Requiring a lambda capturing stuff and be passed around is not what I would call "pay less", when the alt
by simplotek 3y ago
> because it makes you pay less for the same benefit.
Requiring a lambda capturing stuff and be passed around is not what I would call "pay less", when the alternative is just adding a block and instantiate a std::lock_guard
- Someone 3y agoFuller quote: “I think the suggested change is better because it makes you pay less for the same benefit” The change suggested in this part of this discussion is by user “Blackthorn” in https://news.ycombinator.com/item?id=35464828 https://news.ycombinator.com/item?id=35464828. It says: > Neat idea. Though I think having to pass a lambda for anything you want to do with the fields is awful ergonomics. > Maybe instead combine the two ideas. MutexProtected<T> but can be locked with MutexProtected<T>::lock() which returns a MutexLocked<T> object. That object then cleans up the lock when it goes out of scope, and also provides direct access to the enclosed type. User “dietr1ch” replied in https://news.ycombinator.com/item?id=35465610 https://news.ycombinator.com/item?id=35465610 he wanted to pay with a lambda to make it clear a lock is taken. I tried to clarify that Blackthorn‘s suggestion would make that clear without requiring that lambda.