Asynchronous Programming in C++ - Structured Concurrency
Course objectives
After completing this course you will be able to:
- identify the limitations of
std::threadandstd::future - use coroutines to implement asynchronous tasks
- design asynchronous algorithms according to the Structured Concurrency paradigm
- build complex asynchronous pipelines using standard Sender adaptors
- implement error handling and task cancellation in asynchronous workflows
- leverage
std::taskfrom C++26 for seamless coroutine-based execution
Course syllabus
Evolution of Asynchrony in C++ (from C++11 to C++26)
- Problems with the Classical Approach
- Limitations of
std::thread,std::futureandstd::promise - Resource management in callback-based implementations
- Limitations of
- Coroutines in C++20
- Structured Concurrency in C++26 – Senders/Receivers
Coroutines
- Coroutines as a Generalization of Functions
- Coroutine Mechanics in C++
- Suspension points –
co_await - Coroutine return types
- The
promise_typeinterface - Coroutine handle –
std::coroutine_handle
- Suspension points –
- Awaiters & Awaitables
- Creating Custom Task Types
- Implementing Task and Generator types
- Symmetric Transfer
Senders/Receivers – std::execution
- The Three Pillars of Abstraction:
- Schedulers – managing execution time and context (thread pools, GPU, execution contexts)
- Senders – describing asynchronous operations (lazy evaluation)
- Receivers – handling results, errors, or cancellation
- Composition of Asynchronous Operations
- Building pipelines using adapters
- Asynchronous algorithms
- Cancellation of Asynchronous Operations
- Error Handling in Asynchronous Algorithms
- Integration with Coroutines –
std::task- Awaitable Senders
Prerequisites
Attendance of our Multithreading in C++ course or equivalent experience with C++