Executing different tasks in parallel
Now, it is time to make our tasks_processor process tasks in multiple threads. How hard can this be?
Getting started
You will need to read the first recipe from this chapter. Some knowledge of multithreading is also required, especially reading the Manipulating a group of threads recipe.
Link this recipe with the boost_system and boost_thread libraries. Define BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS to bypass restrictive library checks.
How to do it...
All we need to do is to add the start_multiple method to our tasks_processor class:
#include <boost/thread/thread.hpp>
class tasks_processor {
public:
// Default value will attempt to guess optimal count of threads.
static void start_multiple(std::size_t threads_count = 0) {
if (!threads_count) {
threads_count = (std::max)(static_cast<int>(
boost::thread::hardware_concurrency()), 1
);
}
// First thread is the current...