capy: thread_pool use
I am considering a use of capy that looks like the following: for (auto i = 0; i < m; ++i) { capy::thread_pool pool(0); for (auto j = 0; j < n; ++j) { capy::run_async(pool.get_executor())(task[j]()); } pool.join(); } I am wondering about the overhead of constructing/deconstructing a heap of thread pools in the outer loop. Does it make sense to pre-construct m of them prior to the loop and then use the ith one within the loop? Is there a better pattern to use for this? Is this the most efficient way to execute a bunch of independent tasks in parallel? This is the first time I am working through capy, so all suggestions are welcome. Thanks a lot. Cheers, Brook
niedz., 1 lis 2026 o 05:07 Brook Milligan via Boost <boost@lists.boost.org> napisaĆ(a):
I am considering a use of capy that looks like the following:
for (auto i = 0; i < m; ++i) { capy::thread_pool pool(0); for (auto j = 0; j < n; ++j) { capy::run_async(pool.get_executor())(task[j]()); } pool.join(); }
I am wondering about the overhead of constructing/deconstructing a heap of thread pools in the outer loop. Does it make sense to pre-construct m of them prior to the loop and then use the ith one within the loop? Is there a better pattern to use for this?
Is this the most efficient way to execute a bunch of independent tasks in parallel?
This is the first time I am working through capy, so all suggestions are welcome.
Hi Brook, I must say, it is very unusual (based on my experience) to want to launch a separate thread pool for each task. Usually, you would have one thread pool per program, or two pools, if you want one group of tasks not to starve the other group. This is also what thread pools are optimised for: perform expensive initialization before the main server loop, upon startup, and then just reuse the threads for different tasks chaply. Are you sure you need a thread pool per task? Also, the cost of starting a thread pool is not only memory directly, but launching threads (which includes preparing stack memory for them). Regards, &rzej;
Thanks a lot.
Cheers, Brook
_______________________________________________ Boost mailing list -- boost@lists.boost.org To unsubscribe send an email to boost-leave@lists.boost.org https://lists.boost.org/mailman3/lists/boost.lists.boost.org/ Archived at: https://lists.boost.org/archives/list/boost@lists.boost.org/message/YWRNNL36...
participants (2)
-
Andrzej Krzemienski -
Brook Milligan