Task execution with Asio
At its core, Boost Asio provides a task execution framework that you can use to perform operations of any kind. You create your tasks as function objects and post them to a task queue maintained by Boost Asio. You enlist one or more threads to pick these tasks (function objects) and invoke them. The threads keep picking up tasks, one after the other till the task queues are empty at which point the threads do not block but exit.
IO Service, queues, and handlers
At the heart of Asio is the type boost::asio::io_service
. A program uses the io_service
interface to perform network I/O and manage tasks. Any program that wants to use the Asio library creates at least one instance of io_service
and sometimes more than one. In this section, we will explore the task management capabilities of io_service
, and defer the discussion of network I/O to the latter half of the chapter.
Here is the IO Service in action using the obligatory "hello world" example:
Listing 11.1: Asio Hello...