Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8031

Using QtConcurrent::run() with QMutex results in unexpected deadlock or warning.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.0
    • Core: QtConcurrent
    • None
    • *Windows XP Professional - 32bit*
      *Visual Studio 2005 Professional*
      *Qt 4.6.0*

    Description

      I have created a simple application that demonstrates this error/behavior. The application is called qtThreads.exe and the source is listed at the bottom of this post.

      In the following examples the application is being run from a Windows console.

      See similar problem with QReadWriteLock: QTBUG-7886

      Example #1 - Works as expected
      qtThreads.exe && echo Test Complete

      • Output:
        Non-Threaded
        Test Complete
        

      Example #2 - Generates warning
      qtThreads.exe wait && echo Test Complete

      • Output:
        Threaded
        QWaitCondition: Destroyed while threads are still waiting
        Test Complete
        

      Example #3 - Generates deadlock
      qtThreads.exe nowait && echo Test Complete

      • Output:
        Threaded
        

      Source Code:

      #include <QtCore/QtConcurrentRun>
      #include <QtCore/QMutex>
      
      #include <iostream>
      
      void foo()
      {
          QMutex lock;
          lock.lock();
          lock.unlock();
      }
      
      int main(int argc, char* argv[])
      {
          if (argc > 1)
          {
              std::cerr << "Threaded\n";
              QFuture<void> future = QtConcurrent::run(&foo);
      
              if (strcmp(argv[1], "wait") == 0)
              {
                  future.waitForFinished();
              }
      
          }
          else
          {
              std::cerr << "Non-Threaded\n";
              foo();
          }
      
          return 0;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            kawninzx6 James Adkison
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes