S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Fiber

Posted on 2013-05-19 19:56 S.l.e!ep.¢% 阅读(613) 评论(0)  编辑 收藏 引用 所属分类: C++
好东西需要分享,不解释.

#define _WIN32_WINNT 0x0500

#include 
<windows.h>
#include 
<tchar.h>
#include 
<stdio.h>

LPVOID P
=NULL;
LPVOID V
=NULL;
LPVOID M
=NULL;

TCHAR chFood[
256]={0};

void abc(LPVOID Param)
{
    _tprintf(_T(
"call abc threadid(%d)\n"), GetCurrentThreadId());
    SwitchToFiber(Param);
}

VOID WINAPI test(LPVOID Param)
{
    
int i = 0;
    i 
= 2;
    _tprintf(_T(
"befor i = %d threadid(%d)\n"), i, GetCurrentThreadId());
    abc( Param );

    i
++;
    _tprintf(_T(
"after i = %d threadid(%d)\n"), i, GetCurrentThreadId());

    SwitchToFiber(Param);
}

int main(void)
{
    M
=ConvertThreadToFiber(NULL);

    V
=CreateFiber(4096, test, M);

    SwitchToFiber(V);

    _tprintf(_T(
"i am back haha thread(%d)\n"), GetCurrentThreadId());

    SwitchToFiber(V);

    DeleteFiber(V);

    
return 0;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理