Boost.Cobalt synchronization functions
Previously, we implemented coroutines, and, in every case in which we called co_await
, we did it for just one coroutine. This means we waited for the result of only one coroutine. Boost.Cobalt has mechanisms that allow us to wait on more than one coroutine. These mechanisms are called synchronization functions.
There are four synchronization functions implemented in Boost.Cobalt:
- race: The
race
function waits for one coroutine out of a set to complete, but it does so in a pseudo-random manner. This mechanism helps avoid starvation of coroutines, ensuring that one coroutine doesn’t dominate the execution flow over others. When you have multiple asynchronous operations and you want the first to finish to determine the flow,race
will allow any coroutine that becomes ready to proceed in a non-deterministic order.When you have multiple tasks (tasks in the generic sense, not Boost.Cobalt tasks) and are interested in completing one...