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