QMutex and unique_lock ?
-
I'm replacing mutex references in a project previously using boost for:
boost::mutex and boost::recursive_mutexThere are also several instances using:
std::unique_lock<boost::mutex> lock(&mutex);https://en.cppreference.com/w/cpp/thread/unique_lock
Is there an equivalent implementation for achieving the same using a QMutex ?
-
I'm replacing mutex references in a project previously using boost for:
boost::mutex and boost::recursive_mutexThere are also several instances using:
std::unique_lock<boost::mutex> lock(&mutex);https://en.cppreference.com/w/cpp/thread/unique_lock
Is there an equivalent implementation for achieving the same using a QMutex ?
-
@jsulm , I see what there are references to recursive, but no reference to unique anywhere.
@SPlatten said in QMutex and unique_lock ?:
I see what there are references to recursive, but no reference to unique anywhere.
Don't get hung up on the name. https://en.cppreference.com/w/cpp/thread/unique_lock has no reference to "unique" anywhere either (except for the name of the class)!
- A
std::unique_lockis simply astd::lock_guardthat can be unlocked/relocked. - A
QMutexLockeris like astd::lock_guardthat can be unlocked/relocked.
Just use
QMutexLockerthe same way you'd usestd::unique_lock. - A
-
@SPlatten said in QMutex and unique_lock ?:
I see what there are references to recursive, but no reference to unique anywhere.
Don't get hung up on the name. https://en.cppreference.com/w/cpp/thread/unique_lock has no reference to "unique" anywhere either (except for the name of the class)!
- A
std::unique_lockis simply astd::lock_guardthat can be unlocked/relocked. - A
QMutexLockeris like astd::lock_guardthat can be unlocked/relocked.
Just use
QMutexLockerthe same way you'd usestd::unique_lock. - A