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

QtConcurrent needs overloads that take QThreadPool argument

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.4.0 Alpha
    • 4.7.1
    • Core: QtConcurrent
    • None

    Description

      The current QtConcurrent is only useful for CPU-bound problems to multiple cores. The abstraction is also valid for handling other parallel tasks, that could benefit from a thread count that is different from the number of cores. Adjusting maxThreadCount on the global thread pool is not an option, as other parts of the program may use QtConcurrent for CPU-bound problems.

      An example could be a piece of code that needs to run several sql queries and read one or more configuration files, perhaps during application startup or when opening some view. QSqlQuery doesn't have an asynchronous API, so running the queries in threads is the only alternative.

      Example use:

      QThreadPool pool;
      pool.setMaxThreadCount(sources.size());
      
      QList<QFuture<SomeResultType> > results;
      for (SourcesList::const_iterator it = sources.begin(); it != sources.end(); ++it) {
       results.push_back(QtConcurrent::run(fetchSomethingFromDb(*it));
      }
      

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            ts Thomas Sondergaard
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes