Re: [cpp]请教关于coroutine的问题

kasicass kasicass at 163.com
Thu Jul 6 00:56:00 CST 2006


 
定义
 
#define STK_UNIT   int
 
struct tcb
{
   STK_UNIT *   pstk;
   ...
};
 
 
pstk指向当前thread/routine的stack。从A切换到B,则将CPU环境pushal到pstk中,然后换到B的pstk,恢复即可。
 
参见uC/OS-II TCB以及task切换的设计,其是multi-tasking的,将起转换为coroutine即可。
 
切换的启动过程可以通过自己设定的 software interrupt ...
 
 
方法的缺点:
好象需要自己建立OS,不能在Linux/Windows上直接建立这些机制 ...
or 自己写个虚拟机 ... 然后在上面再构建 coroutine -_-! ... 
 
 



-----原始邮件-----
发件人:"李慧霸" 
发送时间:2006-07-05 20:28:46
收件人:"cpp" 
抄送:(无)
主题:[cpp]请教关于coroutine的问题


我找了一些coroutine的跨平台实现(源代码),发现里面基本上都用了memcpy来保存、恢复堆栈。这样做可能回造成比较低的效率,有没有哪个是用切换堆栈指针实现的?windows的fiber是怎么做的?


--------
李慧霸
2006-07-05

_______________________________________________
Cpp mailing list
Cpp at codingnow.com
http://codingnow.com/mailman/listinfo/cpp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060706/12b2c50c/attachment.html


More information about the Cpp mailing list