Customizing the thread pool dispatcher

In our previous example, we had to create the thread pool in order to manage certain tasks—fund transfer from one bank account to another. Our goal was to use enough system resources, but not too much. At the same time, we had to take care of busy and available threads and maintain synchronization. Our following example will expand the thread pool making it a lot smarter and have the ability to solve possible problems that could occur during execution.

Instead of iterating through the thread list and waiting for some thread to complete execution, we'll use message passing in order to select the first thread that completes its task and notify the dispatcher. Instead of simply executing a user-defined function ...

Get C++ Multithreading Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.