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

Nested QtConcurrent::map cause deadlock

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Fixed
    • Affects Version/s: 4.8.7, 5.12.0, 6.2.0 Beta4
    • Fix Version/s: 5.15.7, 6.2.1, 6.3.0 Feature Freeze
    • Component/s: Core: QtConcurrent
    • Labels:
      None
    • Environment:
      linux 2.6, gcc 4.8.4, qt 4.8.7

      windows 7, mingw7.3 64bit, qt 5.12.0
    • Platform/s:
      Linux/X11, Windows
    • Story Points:
      21
    • Commits:
      1afd562b0b0bbba02575aa79601f0fae555cfa19 7cd69f9af057f4b48b259004b032f241b72f0de9 (qt/qtbase/6.2) 14b0d9a50f1679daabb0f5a64368006f7a64a189 (qt/tqtc-qtbase/5.15)
    • Sprint:
      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

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

          Activity

            People

            Assignee:
            ievgenii.meshcheriakov Ievgenii Meshcheriakov
            Reporter:
            zuo-heng.deng Zuoheng Deng
            PM Owner:
            Vladimir Minenko Vladimir Minenko
            RnD Owner:
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes