6. C Coroutine Library
● Protothread
○ switch case
● State threads
○ longjmp + setjmp
● couroutine
○ ucontext
7. Protothread
int function(void) {
static int i, state;
switch (state) {
case 0: /* start of function */
for (i = 0; i < 10; i++) {
state = __LINE__ + 2; /* so we will come back to "case __LINE__" */
return i;
case __LINE__:; /* resume control straight after the return */
}
}
}