C++ Coroutines - Gods from the Machine

By Phil Nash

Coroutines seem to work like magic - with the compiler generating a lot of machinery for you. Yet, at the same time, writing them from scratch remains complex with lots of moving parts! Trying to keep them all in your head while learning it is what makes coroutines so hard to master.

But the dance between all those parts and what the compiler does for you is so tight that you can literally let your compiler be your guide. I’ll show how, from a standing start, you can get from no code to a working, useful, coroutine while only needing to know a handful of extra pieces of information.

In ancient Greek theatre puzzling plots were often resolved by external factors - often an actor or prop lowered in from a crane (in Greek, "mēkhanês", or Latin: "mechine"). This came to be called, "deus ex machina" - gods from the machine. We will keep our deus ex machina to a minimum and leave the compiler to teach us the rest.

Finally! Coroutines without the suspense!





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.