Suppose you want to organize the protection of an arbitrary code by a local static mutex:
void MyClass::myMethod() { static QMutex mutex; mutex.lock(); // защищённый код ... mutex.unlock(); } As far as I know, if instead of QMutex is a different local static type (for example, QString ), a “race” can easily happen and, say, two competing streams will create two copies of the object.
Despite the fact that Qt help for QMutex indicates that all methods are thread-safe, there is no certainty that this is true for its constructor.
Would it be in the context of MyClass::myMethod() creating a mutex object at the first call is thread-safe?