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

Deadlock: QThreadPool::start in runnable destructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.15.1
    • 5.10.0
    • Core: Threads
    • None
    • * Manjaro Linux, Kernel Version 4.14.9, x64
       * gcc-Version 7.2.1
       * Qt 5.10.0 gcc_64
       * Qt 5.10.0 from distribution
    • 891b60bbc84ddde077072df3426539c716d47459 (qt/qtbase/dev) 5a4b275a201bfc653a99e8b6ab546573553b79ad (qt/qtbase/5.15)

    Description

      As of the documentation, QThreadPool::start is threadsafe. However, when using it from a destructor of a autodeleted QRunnable subclass, it leads to a (guaranteed) deadlock. Sample code:

      class TestRunnable : public QRunnable {
      public:
          TestRunnable() {
              setAutoDelete(true);
          }
          ~TestRunnable() {
              QThreadPool::globalInstance()->start(new OtherRunnable());
          }
          // ...
      }
      

      I attached a test source file which provokes such a situation. By checking the console output, you can see that QThreadPool::start() never returns.

      Attachments

        For Gerrit Dashboard: QTBUG-65486
        # Subject Branch Project Status CR V

        Activity

          People

            dragly Svenn-Arne Dragly
            SkyCoder Felix Barz
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes