Coroutines switch between caller and callee, for example. you enter the corotuine function and return back to the calling code. Typically (asymmetric) coroutines have two functions for this purpose:
- Caller Summary Function
- suspend function called inside a coroutine
Since you have two functions to switch context, this is called asymmetric. Symmetric coroutines have only one function, which pauses the current context and resumes another. Note that you need to specify which symmetric coroutine should be continued as follows.
Symmetric coroutines can be used to implement user land flows (a symmetric coroutine represents a user flow, the scheduler jumps from one to the next symmetric coroutine, for example, the next user land flow is planned) more efficiently than asymmetric coroutines. This is obvious because symmetric coroutines do not need to return to the caller to resume the next stream of user land. Asymmetric coroutines require more context switches than symmetric coroutines to achieve the same functionality.
Symmetric coroutines - symmetric context switching - are better represented by concepts such as β call with current continuation β (Scheme, Ruby ...). boost.context supports this concept with its implementation of callcc () / continue . Therefore, boost.coroutine2 does not provide a symmetric coroutine coprocessor, but the asymmetric boost.coroutine2 coprocessor is implemented with boost.context callcc () / continued .
source share