Chapter 9. Advanced thread management

This chapter covers

  • Thread pools
  • Handling dependencies between pool tasks
  • Work stealing for pool threads
  • Interrupting threads

In earlier chapters, you’ve been explicitly managing threads by creating std::thread objects for every thread. In a couple of places you’ve seen how this can be undesirable, because you then have to manage the lifetime of the thread objects, determine the number of threads appropriate to the problem and to the current hardware, and so forth. The ideal scenario would be that you could divide the code into the smallest pieces that could be executed concurrently, pass them over to the compiler and library, and say, “Parallelize this for optimal performance.” As we’ll see in chapter ...

Get C++ Concurrency in Action, Second Edition now with O’Reilly online learning.

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