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

QFuture without threads

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: P1: Critical P1: Critical
    • None
    • None
    • Core: Threads
    • None
    • All
    • 13
    • Foundation PM Prioritized

      It would be very useful if QFuture could be used without threads to implement lazy evaluation or to fulfill promises asynchronously in the event loop, such as in this example provided by timblechmann:

      QObject context;
      auto promise = QPromise<int>();
      promise.future().then(&context, [](int fortytwo) {
          qDebug() << fortytwo;
      });
      QTimer::singleShot(100ms, [promise = std::move(promise)]() mutable {
          promise.start();
          promise.addResult(42);
          promise.finish();
      });
      

      Unfortunately, FEATURE_future depends on FEATURE_thread, which prevents using QFuture, for example, with WebAssembly (single-threaded).

      According to fabiankosmale this will require:

      1. do a fine-grained removal of API that only works with threads, and you also need to consider what e.g. QFuture::then or waitForFinished should do without threads available
      2. You would probably need another backend implementation, as the current implementation is tied to threading support (e.g. because it uses QWaitCondition).

      The first usecase for this is to improve sample handling in QtMultimedia, see QSampleCache: use promises to simplify object connections (581826) · Gerrit Code Review (qt-project.org)

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

            manordheim Mårten Nordheim
            johanseg Jøger Hansegård
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change