Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QRecursiveMutex Class Reference

\inmodule QtCore More...

#include <qmutex.h>

+ Inheritance diagram for QRecursiveMutex:
+ Collaboration diagram for QRecursiveMutex:

Additional Inherited Members

- Public Member Functions inherited from QMutex
constexpr QMutex () noexcept
 Constructs a new mutex.
 
void lock () noexcept
 Locks the mutex.
 
bool tryLock (int timeout=0) noexcept
 Attempts to lock the mutex.
 
bool try_lock () noexcept
 
void unlock () noexcept
 Unlocks the mutex.
 
template<class Rep , class Period >
bool try_lock_for (std::chrono::duration< Rep, Period > duration) noexcept
 
template<class Clock , class Duration >
bool try_lock_until (std::chrono::time_point< Clock, Duration > timePoint) noexcept
 

Detailed Description

\inmodule QtCore

Since
5.14

The QRecursiveMutex class provides access serialization between threads.

\threadsafe

The QRecursiveMutex class is a mutex, like QMutex, with which it is API-compatible. It differs from QMutex by accepting lock() calls from the same thread any number of times. QMutex would deadlock in this situation.

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:

\list

  • 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. \endlist
See also
QMutex, QMutexLocker, QReadWriteLock, QSemaphore, QWaitCondition

Definition at line 309 of file qmutex.h.


The documentation for this class was generated from the following file: