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

Nested QtConcurrent::map cause deadlock

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 5.15.7, 6.2.1, 6.3.0 Feature Freeze
    • 4.8.7, 5.12.0, 6.2.0 Beta4
    • Core: QtConcurrent
    • None
    • linux 2.6, gcc 4.8.4, qt 4.8.7

      windows 7, mingw7.3 64bit, qt 5.12.0
    • Linux/X11, Windows
    • 21
    • 1afd562b0b0bbba02575aa79601f0fae555cfa19 7cd69f9af057f4b48b259004b032f241b72f0de9 (qt/qtbase/6.2) 14b0d9a50f1679daabb0f5a64368006f7a64a189 (qt/tqtc-qtbase/5.15)
    • Team 1 Foundation_Sprint 42

    Description

      In some case, I want to use nested QtConcurrent::map(another map in a mapped task), such as following example, but the code can not run forever, it will hang quickly:

      // code placeholder
      #include <cassert>
      #include <QtConcurrentMap>
      #include <QtConcurrentRun>
      #include <QFuture>
      #include <QThreadPool>
      #include <QtTest/QTest>
      #include <QFutureSynchronizer>
      
      struct Task2 { // only calculation
          typedef void result_type;
          void operator()(int count) {
              int k = 0;
              k += count;
              assert(k >= 0);
          }
      };
      
      struct Task1 { // will launch some other concurrent map
          typedef void result_type;
          void operator()(int count) {
      
              QVector<int> vec;
              vec.push_back(count); // only one element
              Task2 task;
      
              QFuture<void> f = QtConcurrent::map(vec.begin(), vec.end(), task);
              {
                  // with out releaseThread before wait, it will hang directly
                  QThreadPool::globalInstance()->releaseThread();
                  f.waitForFinished(); // BUG: may hang there
                  QThreadPool::globalInstance()->reserveThread();
              }
          }
      };
      
      
      int main() {
          int count = 0;
          for (;;) {
              QVector<int> vec;
              vec.push_back(0); // only one element
              // launch a task with nested map
              Task1 task; // Task1 will have nested concurrent map
              QFuture<void> f = QtConcurrent::map(vec.begin(), vec.end(),task);
      
              f.waitForFinished(); // BUG: may hang there
      
              count++;
      
              qDebug() << count;
          }
          return 0;
      }
      

       

       

       

      Attachments

        1. qt_6.4.0.patch
          0.5 kB
        2. qt_6.4.0-1.patch
          0.6 kB

        Activity

          People

            ievgenii.meshcheriakov Ievgenii Meshcheriakov
            zuo-heng.deng Zuoheng Deng
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: