Revisiting the shared memory problem through coroutines in C++
One of the issues we had with condition variables was synchronization during process startup. In other words, for the producer-consumer example, we didn’t know which threads were going to be first. We synchronized the code through a condition variable – its mutex, together with a predicate in order to handle the correct sequence of events. Otherwise, we would’ve risked losing information or ending in a deadlock. For a good portion of this book’s example preparations, we got to this situation, which made the writing experience even better. But coroutines provide another way of doing it, which could be more efficient at times and simpler to use (after you get used to the interface of coroutines as it is not the easiest to grasp).
The next example is motivated by the awaitable-awaiter pattern. It is similar to the condition variable, but it doesn’t use such synchronization primitives....