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

QFuture hangs when continuation uses a context object and is resolved from the same thread

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6.2, 6.7.0 Beta1, 6.8.0 FF
    • 6.6.0
    • Core: QtConcurrent
    • None
    • Windows 11 2H22, MSVC 19.36.32535.0 64bit
    • Windows
    • 59e21a536 (dev), f89d80c90 (6.7), d5528cdec (6.6)

    Description

      QPromise::finish() hangs when QFuture::then() continuation uses a context QObject and the promise is resolved from the same thread as the context object's parent thread.

      Minimal repro case:

      #include <QCoreApplication>
      #include <QPromise>
      #include <QFuture>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          QObject *context = new QObject;
      
          QPromise<int> p;
          QFuture<int> f = p.future();
      
          f.then(context, [](int a) {
              qDebug("result is %d", a); // this is never called
          });
      
          p.start();
          p.addResult(43);
          p.finish(); // this never returns
      
          return app.exec();
      }
      

      Note, if we don't pass the context parameter, it works just fine, i.e. the continuation is executed and p.finish() returns.

      It also works fine, if the promise is resolved in different thread.

      Attachments

        Issue Links

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

          Activity

            People

              cnn Qt Core & Network
              martin_ky Martin Kutny
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes