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

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

XMLWordPrintable

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

      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.

      Example #1 - Works as expected
      qtThreads.exe

      • Output:
        Non-Threaded
        

      Example #2 - Generates warning
      qtThreads.exe wait

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

      Example #3 - Generates deadlock
      qtThreads.exe nowait

      • Output:
        Threaded
        

      Source Code:

      #include <QtCore/QtConcurrentRun>
      #include <QtCore/QReadWriteLock>
      
      #include <iostream>
      
      void foo()
      {
          QReadWriteLock lock;
          lock.lockForRead();
          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;
      }
      

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes