|
-
October 11th, 2007, 07:51 AM
#1
Invalid thread handle
Hello, I am creating a thread (let's call it thread B) from within another thread (thread A) , and saving the thread handle returned by AfxBeginThread. Before returning from thread A, I wait for thread B to terminate, using WaitForSingleObject with the thread handle. Problem is: if thread B already terminated (it terminates when the thread function returns, not by endthread) by the time I call WaitForSingleObject, this routine fails, returning WAIT_FAILED, and when I call GetLastError I get error no. 6: "The handle is invalid." Since I have handles leak, I suspect that the handle is not really closed (there is no point to call CloseHandle on it, if it's invalid). Any idea why the handle becomes invalid? maybe the fact that I create the thread from withing another thread is problematic? thanks
It is nice to be important, but more important to be nice.
-
October 16th, 2007, 01:26 AM
#2
Re: Invalid thread handle
CWinThread invalidates the handle when the thread ceases to exist. That would explain it.
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|