A walkthrough of implementing coroutines in plain C using setjmp/longjmp combined with a small amount of x86-64 inline assembly. The post demonstrates a working iterator example with a start/yield/next API, explains why a separate stack must be allocated and switched, and covers portability pitfalls such as stack growth direction and frame pointer handling. It also references makecontext-based alternatives and Tony Finch's assembly-free approach using caller-stack allocation.

11m read timeFrom embeddedrelated.com
Post cover image