Compatibility Members for QMutex

以下成员源于类 QMutex are part of the Qt compatibility layer. We advise against using them in new code.

公共函数

QMutex (bool recursive )
bool locked ()

成员函数文档编制

QMutex:: QMutex ( bool recursive )

Use the constructor that takes a RecursionMode parameter instead.

bool QMutex:: locked ()

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;
}