上代码:
// FiberThread.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define _WIN32_WINNT _WIN32_WINNT_LONGHORN
#define WINVER _WIN32_WINNT_LONGHORN
#include <windows.h>
#include <stdio.h>
#include <winbase.h>
DWORD gdwOne = 0;
//纤程的执行函数 最后需要切换纤程
VOID CALLBACK FiberProc( PVOID lpParameter)
{
PVOID pFiberMain = lpParameter;
FlsSetValue(gdwOne,pFiberMain);
SwitchToFiber(pFiberMain);
}
VOID NTAPI FLS_Callback_function ( IN PVOID lpFlsData )
{
printf("Fls function\n");
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dMain = 100;
DWORD dOtherFiber = 1000;
//线程转换为纤程
PVOID pFibermain = ConvertThreadToFiber(&dMain);
//局部存储
gdwOne = FlsAlloc(FLS_Callback_function);
//创建一个纤程
PVOID pFiberCounter = CreateFiberEx(0,0,FIBER_FLAG_FLOAT_SWITCH, FiberProc, pFibe