QMutex on Qt 5.7.0
-
I try to recompile an application developed on Qt 5.5.0 on new Qt 5.7.0, the first problem that compiler has shown is that QMutex include miss (but Qt 5.5.0 doesn't give me this problem).
After i have added QMutex include and all compile, but when application is closed, it seems that qmutex is not destroyed and i receive an exception .
Are there different Handling on QMutex on Qt 5.5.0 and Qt 5.7.0 ?
-
Hi
Its hard to imagine huge changes as its same uses cases still.
What exception is shown? -
@e.capasso said in QMutex on QT 5.7.0:
QMutex: destroying locked mutex
That's pretty descriptive. You don't unlock a mutex and you exit the application instead. You should fix this so you get a graceful close sequence (i.e. freeing your resources).
-
@e.capasso said in QMutex on QT 5.7.0:
why the same project in QT5.5.0 closes itself graceful
It doesn't close gracefully, you get a fat warning from Qt. Why it works no one can tell you. Closing the application while a mutex is locked falls into the "undefined behavior" section, thus it may work (as with Qt 5.5) or it may not (as with Qt 5.7).
-
@e.capasso said in QMutex on QT 5.7.0:
why the same project in QT5.5.0 closes itself graceful?
It was not graceful. You must make sure that your program unlocks all mutexes before quitting.
Destroying a locked mutex leads to undefined behaviour. So, your program didn't crash in Qt 5.5.0 only because you were "lucky".
See the code and documentation at https://code.woboq.org/qt5/qtbase/src/corelib/thread/qmutex.cpp.html#188 -- The warning about undefined behaviour is supposed to be documented at http://doc.qt.io/qt-5/qmutex.html but it seems to be missing.