I have a multi-threaded application with an object that has re-entrant functions. I am trying to make my object thread safe by including a mutex. I am wondering if you can do multiple QMutexLocker locker on one instance of mutex within the same thread. For instance:

notice in my connect function I am calling my Disconnect function that also tries to do a QMutexLocker on global variable mutex.

Tien

]]>https://forum.qt.io/topic/1544/threadingRSS for NodeSun, 15 Sep 2019 08:27:03 GMTTue, 02 Nov 2010 18:34:46 GMT60I have a multi-threaded application with an object that has re-entrant functions. I am trying to make my object thread safe by including a mutex. I am wondering if you can do multiple QMutexLocker locker on one instance of mutex within the same thread. For instance:

notice in my connect function I am calling my Disconnect function that also tries to do a QMutexLocker on global variable mutex.

Tien

]]>https://forum.qt.io/post/1544https://forum.qt.io/post/1544Tue, 02 Nov 2010 18:34:46 GMTbq. I am wondering if you can do multiple QMutexLocker locker on one instance of mutex within the same thread.

Yes. When the mutex is locked, all other functions that require it to be unlocked, will wait (block) till the mutex is unlocked.

Edit: But in your case, you will halt the thread forever. You can not call a function that requires the mutex to be unlocked from within a function that actually locks the mutex unless you unlock the mutex first. But in your case, the mutex is unlocked when the connect() function goes out of scope (the mutex locker is destroyed)

]]>https://forum.qt.io/post/59160https://forum.qt.io/post/59160Tue, 02 Nov 2010 18:53:58 GMTis it true i can set the recursive mode for the mutex to recursive for me to continue my process? How can I set the recursive mode? I tried the following but get an error:

]]>https://forum.qt.io/post/59161https://forum.qt.io/post/59161Tue, 02 Nov 2010 19:05:25 GMTi got it to work.... QMutex has to be declare as a QMutex pointer for me to do a new....
]]>https://forum.qt.io/post/59165https://forum.qt.io/post/59165Tue, 02 Nov 2010 19:13:59 GMTQMuted should be QMutex?
]]>https://forum.qt.io/post/59166https://forum.qt.io/post/59166Tue, 02 Nov 2010 19:15:28 GMT