Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.3.0 Alpha
-
None
Description
boost.asio has this neat concept of "strands". (compare https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/reference/strand.html)
they basically function as "executor" inside a thread pool, which ensure sequential execution of all work which is dispatched in this strand. it might be worth having a similar concept in QtConcurrent.
—
`QtConcurrent::run()` currently uses a `QThreadPool` as argument. the semantics of "strand" is equivalent to using `QtConcurrent::run` with a `QThreadPool` that only has a single worker thread. this is perfectly fine of course, but it requires users to spin up a custom thread and one cannot re-use existing thread pools.
so i could imagine something like:
QtConcurrent::strand myStrand(QThreadPool::globalInstance()); // wrap global threadpool for (int index : {1, 2, 3, 4}) { QtConcurrent::run(myStrand, [index] { profit(index); // called sequentially on the global thread pool ); }
—
one could achieve the same by chaining futures, but that's not always practical to do