Last active
August 29, 2015 13:57
-
-
Save whoo24/9905977 to your computer and use it in GitHub Desktop.
Using fiber on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <windows.h> | |
PVOID ParentFiber; | |
VOID WINAPI logicFiber (PVOID pvParam) { | |
printf("logicFiber\n"); | |
SwitchToFiber(ParentFiber); | |
} | |
DWORD WINAPI MainThread (PVOID pvParam) { | |
PVOID fiber = ConvertThreadToFiberEx(nullptr, FIBER_FLAG_FLOAT_SWITCH); | |
ParentFiber = fiber; | |
printf("MainThread\n"); | |
PVOID new_fiber = CreateFiberEx(1024, 2048, FIBER_FLAG_FLOAT_SWITCH, logicFiber, nullptr); | |
SwitchToFiber(new_fiber); | |
printf("MainThread\n"); | |
ConvertFiberToThread(); | |
} | |
int _tmain (int argc, _TCHAR* argv[]) { | |
DWORD thread_id; | |
HANDLE thread_handle = CreateThread(nullptr, 0, MainThread, nullptr, 0, &thread_id); | |
WaitForSingleObject(thread_handle, INFINITE); | |
CloseHandle(thread_handle); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment