(GlobalCpp) Coroutines (wonder)land
6 attendees from 2 groups hosting
Hosted by C++TO The Toronto C++ User Group
Details
Damir will give a practical example of using coroutines in socket-based communication.
We will redesign the receiver component, common for both endpoints, for handling the data exchange. We will start with a naïve approach – trying directly to replace existing code with a coroutine and explaining why this is an antipattern. Then we will redesign the receiver to be coroutines “friendly” and how we can reimplement the Server and Client components – to handle multiple connections within a single thread, instead of having one receiver thread per connection.
We will also explore how we can employ custom allocators to override the coroutine default allocation strategy – allocation on the heap. I’ll describe the implementation, starting with the fixed-size stack allocator – with internal memory storage on the stack, and how to build the pool of fixed-size allocators of different sizes on top of it. We will wrap this implementation into std::pmr::memory_resource interface to have a polymorphic, type-erased allocator that can be used along with std::pmr containers. We will use it to override the coroutine default allocation strategy, allocating memory primarily on the stack, with a fallback strategy – allocating on the heap, only when the capacity of the internal stack storage is exhausted.



