QRecursiveMutex 類提供在綫程之間串行化訪問。 更多...
| 頭: | #include <QRecursiveMutex> |
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
注意: 此類的所有函數 綫程安全 .
| QRecursiveMutex () | |
| ~QRecursiveMutex () | |
| void | lock () |
| bool | tryLock (int timeout = 0) |
| bool | try_lock () |
| bool | try_lock_for (std::chrono::duration<Rep, Period> duration ) |
| bool | try_lock_until (std::chrono::time_point<Clock, Duration> timePoint ) |
| void | unlock () |
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:
另請參閱 QMutex , QMutexLocker , QReadWriteLock , QSemaphore ,和 QWaitCondition .
[constexpr]
QRecursiveMutex::
QRecursiveMutex
()
構造新的遞歸互斥。互斥是在解鎖狀態下創建的。
銷毀互斥。
警告: 銷毀鎖定互斥可能導緻未定義行為。
Locks the mutex. If another thread has locked the mutex then this call will block until that thread has unlocked it.
Calling this function multiple times on the same mutex from the same thread is allowed.
另請參閱 unlock ().
試圖鎖定互斥。此函數返迴
true
若獲得鎖;否則返迴
false
. If another thread has locked the mutex, this function will wait for at most
timeout
milliseconds for the mutex to become available.
注意:傳遞負數作為 timeout 相當於調用 lock (), i.e. this function will wait forever until mutex can be locked if timeout 為負。
If the lock was obtained, the mutex must be unlocked with unlock () 在另一綫程可以成功鎖定它之前。
Calling this function multiple times on the same mutex from the same thread is allowed.
試圖鎖定互斥。此函數返迴
true
若獲得鎖;否則返迴
false
.
提供此函數是為兼容標準庫概念
Lockable
。它相當於
tryLock
().
試圖鎖定互斥。此函數返迴
true
若獲得鎖;否則返迴
false
。若另一綫程有鎖定互斥,此函數將等待至少
duration
為使互斥變得可用。
注意:傳遞負值持續時間作為 duration 相當於調用 try_lock ()。此行為不同於 tryLock ().
If the lock was obtained, the mutex must be unlocked with unlock () 在另一綫程可以成功鎖定它之前。
Calling this function multiple times on the same mutex from the same thread is allowed.
試圖鎖定互斥。此函數返迴
true
若獲得鎖;否則返迴
false
. If another thread has locked the mutex, this function will wait at least until
timePoint
為使互斥變得可用。
注意:傳遞 timePoint which has already passed is equivalent to calling try_lock ()。此行為不同於 tryLock ().
If the lock was obtained, the mutex must be unlocked with unlock () 在另一綫程可以成功鎖定它之前。
Calling this function multiple times on the same mutex from the same thread is allowed.
Unlocks the mutex. Attempting to unlock a mutex in a different thread to the one that locked it results in an error. Unlocking a mutex that is not locked results in undefined behavior.
另請參閱 lock ().