I'm trying to create a multi-threaded DLL/Exe in native Win32 API. I am new to threading in Win32 (done in .NET). What I do not know is how to "return" to the main thread using event style functionality. i.e.
So after MyThread() finishes, how do I call a function on the parent thread that will then do its appropriate functionality. Such as "int FinishedLoading(void)"
#include <windows.h> #include <stdio.h> #include <time.h> DWORD WINAPI MyThread(LPVOID); int main(void) { DWORD iID[2]; HANDLE hThreads[2]; DWORD waiter; srand((unsigned)time(NULL)); hThreads[0] = CreateThread(NULL, 0, MyThread, "T1", NULL, &iID[0]); hThreads[1] = CreateThread(NULL, 0, MyThread, "T2", NULL, &iID[1]); waiter = WaitForMultipleObjects(2, hThreads, TRUE, INFINITE); return 0; } DWORD WINAPI MyThread(LPVOID n) { char *name = (char *)n; for(int i=0; i<10; i++) { printf("Thread %s: i=%d\n", name, i); if ("T1" == name) SleepEx(100, false); else SleepEx(200, false); } return 0; }
So after MyThread() finishes, how do I call a function on the parent thread that will then do its appropriate functionality. Such as "int FinishedLoading(void)"