Coroutines are one of the most significant language additions in C++20.
It is a powerful but also quite complex feature. It allows us to run many concurrent coroutines with no overhead. The coroutine framework is open-ended, meaning that library authors may develop coroutine libraries exposing various high-level semantics. Unfortunately, there is no coroutine support library in C++20. C++23 will only provide `std::generator`, and some more types are expected to come only with C++26. This is the reason why we not only need to understand the coroutine framework (both language and library parts) and how to use coroutine tools but also learn how to write such utilities by ourselves.
During the workshop, we will work with the latest compiler version thanks to the Compiler Explorer, so no special environment preparation is needed.
TRAINING HIGHLIGHTS
- Detailed discussion of coroutine machinery and its suspend and customization points
- Understanding the differences between a coroutine return type, coroutine promise type, coroutine traits, coroutine handle, an awaiter, and an awaitable
- Implementing synchronous and asynchronous tasks in eager and lazy ways and discussing the essential differences
- "Teaching" some common and custom C++ types on how to become awaitables, and discussing the potential issues and solutions with different approaches
- Developing custom generators and learning how to connect them to the C++ range adaptor objects processing pipeline
- Learning how to deal with coroutines from regular functions like `main()`
- Why and how to improve our implementations with the coroutine symmetric control transfer
- Using C++20 concepts and constraints, ranges and views, and new concurrency tools in action
TRAINING AGENDA
The following plan is an initial proposal for the training material. The final agenda is always created based on the individual pre-training analysis of the client's requirements and constraints.
- Coroutines
- Coroutine keywords, restrictions, suspend points
- Coroutine return type
- std::coroutine_traits
- Coroutine promise interface
- std::coroutine_handle
- Awaiters and Awaitables
- Symmetric Control Transfer
- C++ exceptions support
- Eager and Lazy Tasks
- async with coroutines
- sync_await
- Generators
- Custom allocator support
- Coroutine support libraries