Posted on 2013-05-19 19:56
S.l.e!ep.¢% 阅读(622)
评论(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;
}