On Nov 1, 2026, at 10:54, Vinnie Falco via Boost <boost@lists.boost.org> wrote:
On Sun, Nov 1, 2026 at 8:49 AM Brook Milligan via Boost < boost@lists.boost.org> wrote:
I am wondering about the overhead of constructing/deconstructing a heap of thread pools in the outer loop.
Seems fine to me.
I interpret this to mean that it is correct code, but (given other comments) perhaps not the most efficient.
...is there another way to ensure that one group is complete before the next starts, even with one thread_pool?
You could build a synchronizer which counts down for each task and then unblocks. Your function with the loops would have to be a coroutine. This would let you construct the thread pool once (or even pass it in as a parameter).
OK, good idea. I’m now beginning to understand when_all(), and see that it can take a vector of tasks. That would seem to handle the inner loop. Does this seem like the right path forward? capy::thread_pool pool(0); capy::run_async(pool.get_executor()) ( [=]() -> capy::task<> { std::vector<capy::task<capy::results<>>> jobs; for (auto i = 0; i < m; ++i) { jobs.reserve(n); for (int j = 0; j < n; ++j) jobs.push_back(make_job(i,j)); auto [ec] = coawait capy::when_all(std::move(jobs)); } }()); pool.join(); Thanks a lot for your help. Both coroutines and capy are new to me, so I appreciate the suggestions. Cheers, Brook