QRecursiveMutex 類

QRecursiveMutex 類提供在綫程之間串行化訪問。 更多...

頭: #include <QRecursiveMutex>
qmake: QT += core
Since: Qt 5.14
繼承: QMutex (private)

該類在 Qt 5.14 引入。

注意: 此類的所有函數 綫程安全 .

公共函數

QRecursiveMutex ()
~QRecursiveMutex ()

詳細描述

QRecursiveMutex 類是互斥的像 QMutex ,采用可兼容 API。它不同於 QMutex 通過接受 lock () 調用來自同一綫程任意次數。 QMutex 在這種情況下,會死鎖。

QRecursiveMutex is much more expensive to construct and operate on, so use a plain QMutex whenever you can. Sometimes, one public function, however, calls another public function, and they both need to lock the same mutex. In this case, you have two options:

  • Factor the code that needs mutex protection into private functions, which assume that the mutex is held when they are called, and lock a plain QMutex in the public functions before you call the private implementation ones.
  • Or use a recursive mutex, so it doesn't matter that the first public function has already locked the mutex when the second one wishes to do so.

另請參閱 QMutex , QMutexLocker , QReadWriteLock , QSemaphore ,和 QWaitCondition .

成員函數文檔編製

QRecursiveMutex:: QRecursiveMutex ()

構造新的遞歸互斥。互斥是在解鎖狀態下創建的。

另請參閱 lock () 和 unlock ().

QRecursiveMutex:: ~QRecursiveMutex ()

銷毀互斥。

警告: 銷毀鎖定互斥可能導緻未定義行為。