Threading question
Is it possible to close a thread handle while the thread is still running? Will it affect the thread?
Just wondering because i currently do:
// Close our client networking socket
closesocket(m_ClientSocket);
// Wait for our listening thread to exit
WaitForSingleObject((HANDLE)m_hListenThread, INFINITE);
// Close the handle of our listening thread
CloseHandle((HANDLE)m_hListenThread);
And well, this prevents me from closing the thread from within itself, i cannot wait for single object from within the thread, so i was wondering if i could just do:
// Close our client networking socket
closesocket(m_ClientSocket);
// Close the handle of our listening thread
CloseHandle((HANDLE)m_hListenThread);
And let the thread run out by itself when it figures the socket is closed. Will this create any memory leaks? problems?
The first bit of code you gave is pretty much correct, but instead of just calling
codeka.com - Just click it.
closesocket
you should also be calling shutdown
on the socket. If I had my way, I''d have all of you shot!
codeka.com - Just click it.
It was a question about threading! :D
And, uh, shutdown is only for TCP sockets buddy.
[edited by - Max_Payne on October 5, 2002 12:40:38 PM]
And, uh, shutdown is only for TCP sockets buddy.
[edited by - Max_Payne on October 5, 2002 12:40:38 PM]
Well you never said that. And I told you that what you''re doing in the first piece of code is correct, so it must be somewhere else that''s not right.
After reading your original post, I''m wondering: where are you putting this code? It should be in some other thread, not the thread that''s supposed to be closing...
codeka.com - Just click it.
After reading your original post, I''m wondering: where are you putting this code? It should be in some other thread, not the thread that''s supposed to be closing...
If I had my way, I''d have all of you shot!
codeka.com - Just click it.
You can close the thread handle anytime you want. Nothing will happen to the thread. The only effect is that the thread will disappear immediately when the thread function exits rather than sitting around as a zombie waiting for you to close the handle.
-Mike
-Mike
-Mike
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement