r/cpp • u/shakmak_iitk • 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
1
u/shakmak_iitk Dec 26 '23
You do not enforce a happens before relationship between the submitter and worker: You can submit when Pool has finished last submitted tasks and is in Pause state.
would be sufficient to use release from the workers and acquire from the submitter: Thanks, I have updated it to make use of related memory ordering
myrunningworkersis not maintained in a thread safe way:numRunningWorkersis std::atomic so thread-safe.myIsRunningThis is a vector where each thread reads/writes to its dedicated index which is also thread-safe.you have a number of control variables that you maintain but don't use:
1.myIsRunning maintains a bool for each thread to store if it has finished its work.myrunningworkersis used to check if all threads has finished.I would point out that openmmp: I don't want to add extra dependency and also creating this threadPool will help me learn :)