Book Image

Learning Boost C++ Libraries

By : Arindam Mukherjee
Book Image

Learning Boost C++ Libraries

By: Arindam Mukherjee

Overview of this book

Table of Contents (19 chapters)
Learning Boost C++ Libraries
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Boost Coroutine


Coroutines are functions that can yield or relinquish control to another coroutine, and then given control back, resuming from the point at which they earlier yielded. The state of automatic variables is maintained between a yield and the resumption. Coroutines can be used for complex control flow patterns with surprisingly simple and clean code. The Boost Coroutine library provides two types of coroutines:

  • Asymmetric coroutines: Asymmetric coroutines distinguish between a caller and a callee coroutine. With asymmetric coroutines, a callee can only yield back to the caller. They are often used for unidirectional data transfer from either the callee to caller, or the other way.

  • Symmetric coroutines: Such coroutines can yield to other coroutines, irrespective of who the caller was. They can be used to generate complex cooperative chains of coroutines.

When a coroutine yields control, it is said to be suspended—its registers are saved and it relinquishes control to another function...