Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.7.1
-
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));
}