4 ms·
A pattern for easier slower concurrency as lambdas aren't free. If the code under the mutex is trivial, this cost of using lambdas will be noticeable, especiall
by eps 4y ago
A pattern for easier slower concurrency as lambdas aren't free. If the code under the mutex is trivial, this cost of using lambdas will be noticeable, especially in fast paths. Might be worth looking at the resulting assembly first if you are looking to adapt this in your codebase.
- gpderetta 4y agoAside from lambdas being cheap abstractions in C++, any code under a mutex is likely not the fast path anyway.
- saagarjha 4y agoI mean, some code is all slow paths ;)
- ot 4y agoLambdas are free. Unless the class type-erases the callback (and MutexProtected doesn't), and the callback is not huge, the compiler is virtually guaranteed to inline it.
- huhtenberg 4y agoIt can go both ways. Clang will inline everything - https://godbolt.org/z/v19P1W9sj https://godbolt.org/z/v19P1W9sj MSVC will not, even with O2 - https://godbolt.org/z/naovTxncs https://godbolt.org/z/naovTxncs > Might be worth looking at the resulting assembly first if you are looking to adapt this in your codebase.
- akling 4y agoAFAIK if you use a templated type for the callback (as you should), it will be inlined by modern compilers at any optimization level other than -O0. :)