O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required