Important: Please read the Qt Code of Conduct -

QMutex: destroying locked mutex What the ***?

  • When closing my app I get
    QMutex: destroying locked mutex
    I do not get the reason of this.
    I found this messge in sources, but I do not get what is the problem and how to fix it.

    193	{
    194	    QMutexData *d = d_ptr.load();
    195	    if (isRecursive()) {
    196	        delete static_cast<QRecursiveMutexPrivate *>(d);
    197	    } else if (d) {
    198	#ifndef QT_LINUX_FUTEX
    199	        if (d != dummyLocked() && static_cast<QMutexPrivate *>(d)->possiblyUnlocked.load()
    200	            && tryLock()) {
    201	            unlock();
    202	            return;
    203	        }
    204	#endif
    205	        qWarning("QMutex: destroying locked mutex");
    206	    }
    207	}

    The mutex is in global static object (instance of singlton) and is used from other thread (it has queued connection)
    What the problem is?

  • Lifetime Qt Champion


    Well, did u use a QMutex in your app ?

    Or did you use a QThread ? If you dont stop it correctly it might say so.

  • @mrjj i HAVE 3 THREADS in the app.
    GUI thread, Worker thread, tasks queue manager

    I use QMutex in queue object in methods which enqueue and dequeue the queue because the queue is accessed from Worker thread, tasks queue manager threads.

    the way I exit threads is smth like

    CalculatingThread::~CalculatingThread() {
        if(!wait(3000)) //Wait until it actually has terminated (max. 3 sec)
            terminate(); //Thread didn't exit in time, probably deadlocked, terminate it!
            wait(); //We have to wait again here!

  • Lifetime Qt Champion

    @Kofr and are you sure the mutex is not locked whe you exit your program ?

  • @Kofr
    I you place breakpoint at line #205 of ~QMutex() you can see which of your mutexes is the culprit, which may help you.

Log in to reply