PDA

View Full Version : Mutex unlock without locking it



^NyAw^
23rd September 2010, 17:19
Hi,

My application locks a QMutex into a try catch statment. The problem is that if an exception is raised, I don't know if the mutex is locked or not, and if I call "unlock" I get an application crash with a message like "a mutex must be unlocked in the same thread that locked it".
QMutex class don't provide any method to know if it is locked.

A solution could be to declare a boolean variable to use it as "mutex_locked" ?

Thanks,

igor
23rd September 2010, 18:17
http://doc.qt.nokia.com/4.7/qmutexlocker.html

Use a QMutexLocker, within the scope of the method, to lock it.
When it goes out of scope, the QMutexLocker is destroyed and the mutex is unlocked.