mutable
was made for this kind of stuff. Namely, mutable
applies to things that don't take part in the logical constness of an object. (If one value is "logically constant", it means the 'primary' values are constant; the value of the object, from the outside, cannot change.)
The value of your object is independent from the state of the mutex (it's only an implementation detail to provide consistency, and it's state is not known outside the class), which is a good sign your mutex should be mutable
.
Note, you should not go the const_cast
route. This leads to undefined behavior if you did:
const Foo f;
Bar b;
f.getBar(b); // takes const off of mutex, modifies (bang you're dead)