[vlc-devel] [PATCH] Make mutexes mutable

Rémi Denis-Courmont remi at remlab.net
Tue Jan 9 13:27:06 CET 2018


On mardi 9 janvier 2018 13:19:22 EET Romain Vimont wrote:
 > In C++, methods writing only members "that do not affect the externally
> visible state of the class" should also be const (mutex, cache, lazy
> evaluation…).
> 
> Typically, using lazy evaluation or cache is an implementation detail,
> it should not change the interface (the method signature).
> 
> That's the very purpose of the "mutable" keyword (logical const).
> 
> Item 16 ("Make const member functions thread safe") of _Effective Modern
> C++_ provides more details and examples.

For the third time, if a method is thread-safe constant, if you can assume 
that the state of the object is unchanged across calls to the method, then it 
does not need a mutex lock, and vice versa.

Making mutex locking and unlocking mutable mostly conceal bugs and bad design 
decisions.


-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list