Hi,
I'm trying to create a basic multi-threading application in C++. The problem is CreateThread() is too slow. Worse still, it doesn't appear to halt my program while the new thread is created, the code after CreateThread() gets executed before the thread is ready. I use Beep() just for debugging purposes. My code is below:
Code:#include <windows.h> #include <tlhelp32.h> DWORD WINAPI runThread(LPVOID args); bool isThreadReady = false; int main() { DWORD dwGenericThread; HANDLE hThread = CreateThread(NULL, 0, runThread, NULL, 0, &dwGenericThread); if (isThreadReady == true) Beep(523, 200); CloseHandle(hThread); return 0; } DWORD WINAPI runThread(LPVOID args) { isThreadReady = true; //Beep(523, 200); return 0; }



LinkBack URL
About LinkBacks




I'm rather new to C++, I'm used to .NET doing my bidding for me. Anyway, I tried WaitForSingleObject; it seemed like the easiest solution to my problem. It worked great in my test application, but when I went to deploy it in my real application it froze. I forgot to mention that all of my code is done under DllMain. I read some reports that using WaitForSingleObject in a dll will cause a deadlock (which it did for me). For now I'm going to look into _beginthreadex, as I do use sprintf_s.
CornedBee
. Oh well, thank you all for your help