Windows核心編程:第12章 纖程
阿新 • • 發佈:2018-07-19
-c pcm == dshow ongl sta lag param rev
Github
https://github.com/gongluck/Windows-Core-Program.git
//第12章 纖程.cpp: 定義應用程序的入口點。 // #include "stdafx.h" #include "第12章 纖程.h" LPVOID g_Covert = nullptr; DWORD g_index = 0; VOID WINAPI FiberFun(LPVOID lpFiberParameter) { //纖程參數 LPVOID pFiberCurrent = GetCurrentFiber(); BOOL bres = IsThreadAFiber(); LPVOID pCurrentData = GetFiberData();//獲取創建纖程時傳遞的參數,pCurrentData==lpFiberParameter==555 //纖程局部存儲區 bres = FlsSetValue(g_index, (PVOID)200); PVOID flsvalue = FlsGetValue(g_index); SwitchToFiber(g_Covert); } VOID NTAPI FlsFun(IN PVOID lpFlsData) { //FlsSetValue多少次,系統調用FlsFun就多少次 //可以主動調用FlsFree刪除Fls槽 //纖程銷毀時也會調用FlsFun } int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { //將線程轉換為纖程 LPVOID pFiberCovert = ConvertThreadToFiberEx(nullptr, FIBER_FLAG_FLOAT_SWITCH); g_Covert = pFiberCovert; //纖程局部存儲區 g_index = FlsAlloc(FlsFun); BOOL bres = FlsSetValue(g_index, (PVOID)100); PVOID flsvalue = FlsGetValue(g_index); //創建纖程 LPVOID pFiberCreate = CreateFiberEx(0, 0, FIBER_FLAG_FLOAT_SWITCH, FiberFun, (LPVOID)555); //切換纖程 SwitchToFiber(pFiberCreate); bres = FlsFree(g_index); //銷毀纖程 DeleteFiber(pFiberCreate); //解除線程的纖程狀態 bres = ConvertFiberToThread(); system("pause"); return 0; }
Windows核心編程:第12章 纖程