[vlc-devel] [PATCH] Make mutexes mutable

Romain Vimont rom at rom1v.com
Tue Jan 9 12:46:12 CET 2018


Le mardi  9 janvier 2018 à 13:41 +0200, Rémi Denis-Courmont a écrit :
> On lundi 8 janvier 2018 21:45:16 EET Romain Vimont wrote:
> > Mutexes must be locked and unlocked even in C++ const methods. To avoid
> > const casts, simply declare them mutable.
> 
> If you need to lock, then your method is not const. Conversely, if the object 
> is guaranteed to be identical before and after the method call, then the 
> methiod does not need to lock any mutex.
> 
> I don't agree with your line of reasoning, and it seems that the C, POSIX and 
> C++ don't either - otherwise they'd have lock and unlock as immutable methods 
> too.

<http://en.cppreference.com/w/cpp/language/cv>

> mutable - applies to non-static class members of non-reference
> non-const type and specifies that the member does not affect the
> externally visible state of the class (as often used for mutexes, memo
> caches, lazy evaluation, and access instrumentation).


More information about the vlc-devel mailing list