Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMutex: destroying locked mutex What the ***?
Forum Updated to NodeBB v4.3 + New Features

QMutex: destroying locked mutex What the ***?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    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.

    QMutex::~QMutex()
    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi

      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.

      K 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi

        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.

        K Offline
        K Offline
        Kofr
        wrote on last edited by
        #3

        @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() {
            quit();
            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!
            }
        }
        
        aha_1980A JonBJ 2 Replies Last reply
        0
        • K Kofr

          @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() {
              quit();
              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!
              }
          }
          
          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • K Kofr

            @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() {
                quit();
                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!
                }
            }
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

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

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved