coroutine in c 备忘

时间:2023-03-09 09:00:02
coroutine in c 备忘

coroutine:

  stackless和stackful

  jmp

  基于switch的trick:

  http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

  文中提到高德纳另有一套办法.

  

#define crBegin static int state=0; switch(state) { case 0:
#define crReturn(x) do { state=__LINE__; return x; \
case __LINE__:; } while (0)
#define crFinish } int function(void) {
static int i;
crBegin;
for (i = 0; i < 10; i++)
crReturn(i);
crFinish;
}