First of all, let's take care of the class that holds all the tasks and provides methods for their execution. We were already doing something like this in the Chapter 5, Multithreading, Creating a work_queue class recipe, but some of the following problems were not addressed:
- A
work_queue
class was only storing and returning tasks, but we also need to execute existing tasks. - A task may throw an exception. We need to catch and process exceptions if they leave the task boundaries.
- A task may not notice a thread interruption. The next task on the same thread may get the interruption instead.
- We need a way to stop the processing of the tasks.
This recipe requires linking with the boost_system
and boost_thread
libraries. A basic knowledge of Boost.Thread
is also required.