7 – Conclusion

Summary

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:

  1. 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.
  2. 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 Object[0] modify data contained in Object[1].
  3. 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.

>> Next, Download Source and Examples >>

Advertisements

One thought on “7 – Conclusion”

  1. Hi, Thanks for the article.. it is too old but me too also too old as still working in
    C++/.. now I am in situation where my engine handles 1000 of devices.. scheduler has to access these devices based on its SDK functions and get data. Along with scheduler user may check them manually too. or may be other user (this engine will be on web server). Now I have saperate classes to handle multiple type of devices.. can you suggest me how to handle this scenario.. means I want scheduler to handle 1000 device and also if user goes for manual check when scheduler is also running!! one device takes atleast 30 second to be tested! can I use this in this scenario? OR I can hard code 20 threads and 20 thread procs (for manual process 10 and for scheduler another 10!!).

    Thanks!
    Chandrak

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s