Asynchronous Programming Using Coroutines
In previous chapters, we saw different methods of writing asynchronous code in C++. We used threads, the basic units of execution, and some higher-level asynchronous code mechanisms, such as futures and promises and std::async
. We will look at the Boost.Asio library in the next chapter. All these methods often use several system threads, created and managed by the kernel.
For example, the main thread of our program may need to access a database. This access may be slow, so we read the data in a different thread so our main thread can go on doing some other tasks. Another example is the producer-consumer model, where one or more threads generate data items to be processed, and one or more threads process those items in a fully asynchronous way.
Both of the preceding examples use threads, also called system (kernel) threads, and require different units of execution, one per thread.
In this chapter, we are going to study a different way...