   [Win32, C++, threads] WaitForSingleObject with thread handle
  Hi, yet another question about threads.I think I understood how to use the WaitForSingleObject method using an EVENT handle. But I couldnt find a good example of how to use it with a THREAD handle. Could someone explain that to me (in a few words, I'll figure out the rest on my own) ?Alternatively, I could ask: what does it mean for a thread to be in a signaled / non signaled state ? Is it just a simple flag which the system attachs to it, without any other signification/purpose ? Is it possible and safe to change that state manually ? From the examples I've found, the threads becomes signaled when it is terminated, which would mean I'm searching the wrong direction. My purpose is quite simple. I got a resource thread that is wainting on another threads to wake it up when a resource is needed. I guess it would be possible to use an event Handle and use the pair SetEvent/ResetEvent. What do you say fellowship of GDNet ?   
  Here's a bare bones example of using WaitForSingleObject with a thread handle. #include <windows.h>#include <tchar.h>// global thread idstatic DWORD g_tid = 0;DWORD WINAPI ThreadFunction(LPVOID lpParameter){   // without this we can not exit msgloop   g_tid = GetCurrentThreadId();   // do stuff - eg. start a msgloop   return 0;}// ---------------------------------------------------------------------------int main(void){   DWORD dwThread, exThread;   // CreateThreadEx   HANDLE hThread = CreateThread(NULL, (DWORD)NULL,  (LPTHREAD_START_ROUTINE)ThreadFunction,  (LPVOID) NULL, (DWORD)NULL, &dwThread);   // suspend main thread until new thread completes   WaitForSingleObject(hThread,INFINITE);   // examine create thread response   if ( !GetExitCodeThread(hThread, &exThread) ) { printf(_T("GetExitCodeThread %08X\n"),GetLastError());   }   // close thread handle   CloseHandle(hThread);   return 0;}(see also)A thread signals when it finishes execution. Signal states are managed by the operating system, it's not a good idea to attempt to manipulate them directly. A SetEvent/ResetEvent pair sounds like a good starting point.   ;  Thank you :) So I shouldnt wait on another thread for anything else that it's termination.(I feel a bit ashamed of being pointed to one of my own topic by someone else [lol])   ;Quote:Original post by jantaThank you :) So I shouldnt wait on another thread for anything else that it's termination.(I feel a bit ashamed of being pointed to one of my own topic by someone else [lol])I didn't even make the connection until you pointed it out. [lol]   ;  - Edited: I'm okay with all that -[Edited by - janta on June 21, 2006 2:23:28 AM]