以下成员源于类 QMutex are part of the Qt compatibility layer. We advise against using them in new code.
| QMutex (bool recursive ) | |
| bool | locked () |
Use the constructor that takes a RecursionMode parameter instead.
Returns true if the mutex is locked by another thread; otherwise returns false.
It is generally a bad idea to use this function, because code that uses it has a race condition. Use tryLock () 和 unlock () 代替。
例如,若有代码像
bool isLocked = mutex.locked();
可以把它重写成
bool isLocked = true; if (mutex.tryLock()) { mutex.unlock(); isLocked = false; }