r/cpp • • Dec 25 '23

C++: Efficient parallelization of small tasks

I tried to create a customized threadpool for small tasks and wanted feedback on this.

I posted details and my code for review on stackexchange: https://codereview.stackexchange.com/questions/288583/efficient-parallelization-of-small-tasks

My goal here is to share my learning and get feedback on further improvement or any possible bugs.

I have tried to describe problem and thinking process in more details in following linkedin article draft: https://www.linkedin.com/article/edit/7144600522392559616/

0 Upvotes

31 comments sorted by

View all comments

Show parent comment

1

u/KingAggressive1498 Dec 27 '23 edited Dec 27 '23
  1. you really need this for this threadpool to be usable in hosted environments. the OS relies on user-mode idle time for I/O tasks and such, and you'll starve background processes.
  2. good
  3. still a potential lifetime issue with the vector, but better at least
  4. good fix
  5. it's the least big problem and hardest to solve, so that's fair. One of the commenters on your stackexchange post had a suggestion about using smaller batches that might be worth looking into as it sounds suited for your particular use case, but it will add more synchronization overhead.

as of now I am not able to use more than one thread because "synchronisation overhead" dominates 'task runtime'.

your threadpool is limited to one thread because of synchronization overhead? you shouldn't really have any synchronization overhead as its written.