Advertisement

Threading question

Started by October 05, 2002 12:07 AM
4 comments, last by Max_Payne 22 years, 4 months ago
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?

Looking for a serious game project?
www.xgameproject.com
The first bit of code you gave is pretty much correct, but instead of just calling 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.



Advertisement
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]

Looking for a serious game project?
www.xgameproject.com
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...

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
Thank you Mike, that is what i wanted to know.

Looking for a serious game project?
www.xgameproject.com

This topic is closed to new replies.

Advertisement