In conclusion, the idea behind a task-based threadpool is to delegate methods and functions from all systems in your program to all threads available on your computer. If you’re going to use this threadpool or attempt to make one yourself, here are a few final things to remember:
- Block as little as possible. You don’t want a function to take too long on one thread, nor do you want it to hold up data that could be used by other threads (if you set up your tasks to do such). When dealing with lists and
std::vectors, try breaking up the data into chunks and send them to the threadpool in multiple tasks.
- Use your own data! Unless you are a multithreading genius, try to use only data that your system has scope to. try to refrain from letting a task in
Objectmodify data contained in
- Don’t send tasks from within another task! You’re asking for a plethora of threading issues right there.
Other than that, have fun! Good luck with threading; its’ not an easy thing to conquer, but when you got it, it feels rewarding. Leave me any comments or questions you have have!
References and Links
ThreadPool.QueueUserWorkItem Method – This is a .NET method for C++, meaning you’d have to set up C++ to use garbage collecting and such. A bit of a hassle, but it does allow you to have to only call this one method to use the thread pool.
Some Notes on Lock-Free and Wait-Free Algorithms – Information and links to various tools and libraries regarding lock-free and wait-free algorithms. It’s targeted at digital audio engineering, but the algorithms apply to all.