I have created a thread as follows,
DWORD Id;
CreateThread(0, 0, think, pcon, 0, &Id);
How to check if the thread is running or if it has come out?
Thanks.
I have created a thread as follows,
DWORD Id;
CreateThread(0, 0, think, pcon, 0, &Id);
How to check if the thread is running or if it has come out?
Thanks.
I have the same question, but temporarily I have mine set up like this:
And then if you want to know if the thread is running or not, just use a simple if(thread) statement.Code:bool thread=false; // just using your example DWORD WINAPI think(LPVOID pcon) { thread = true; // do stuff here thread = false; return whatever; } whatever whatever(whatever) { DWORD Id; CreateThread(0, 0, think, pcon, 0, &Id); }
Save the return value of the CreateThread function.
Use this handle in the WaitForSingleObject function with timeout=0 (or not zero if you want to wait for thread to exit)
When you know where the state of the handle is signaled or not.
The handle is signaled on exit of the thread.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler