how to get the following info. from a thread
i create a thread and got the Handle.
how can i get the following information of the thread?
1. is the thread object signaled? when can it be signaled?
2. is the thread suspended? it is easy but how to get the suspend count?
3. has the thread terminated? what happens to the thread object if the thread funtion quits? reset to NULL?
i looked up the google but could not get clear answer, wish you guys here can help me out, thanks alot!
[477 byte] By [
shelper] at [2007-11-20 0:39:59]

# 2 Re: how to get the following info. from a thread
1. is the thread object signaled? when can it be signaled?The thread (handle) can be said to be in a signalled state in context of wait functions (i.e. it lets them continue) when the thread has ended.
To query if a thread has ended, you can either compare the return value of WaitForSingleObject (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemain4/html/cerefWaitForSingleObject.asp) on the thread handle against WAIT_OBJECT_0 or check the exit code of this thread using GetExitCodeThread (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getexitcodethread.asp) against STILL_ACTIVE.
2. is the thread suspended? it is easy but how to get the suspend count? I don't know why this is important because it implies frequent usage of SuspendThread (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/suspendthread.asp), which is not recommended.
But, the documentation does answer your question -
If the function succeeds, the return value is the thread's previous suspend count; otherwise, it is (DWORD) -1. To get extended error information, use the GetLastError function. And... 3. has the thread terminated? what happens to the thread object if the thread funtion quits? Again, here is what the documentation for CreateThread (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp) has to say -
The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.I hope this post answers your questions...