This is probably notnecessarilyTBB related, but can an tbb::atomic or a tbb::mutex be mutable?
I have this const function, that calls some of my code (can't change the caller), that reads data out from an object.But internally during this call I need to ensure that the data is not being changed by another thread, so I was placing a scoped lock in the call, problem is locking/unlocking require the object to not be constant, since the lock is part of the object. So I'm not sure if I should cast away the the constness of the entire object within the callback, or if its possible to make thesynchronizationprimitive mutable (keyword).
In almost all cases, const gives code generators no useful information and consequently has no effectonlow-level code generation. The reason is twofold:
If the compiler can prove these two reasons do not apply, it has enough information to do the optimization anyway without the const. The few signifcant contexts where an optimizer can exploit const are: