Click to See Complete Forum and Search --> : _endthreadex


dougbrower
April 20th, 1999, 12:41 PM
The documentation for _endthreadex stipulates that you must call ::CloseHandle()yourself when your thread terminates, but it is not clear to me how the needed handle is obtained. _beginthreadex returns an unsigned long which the documentation describes as a "handle" to the thread, but Winnt.h typedefs a HANDLE as a void pointer -- not an unsigned long. Needless to say, I'm leery of blindly casting an unsigned long to a void*. Does anyone have any ideas about this?

Thanks

Doug Brower

Jason D
December 1st, 1999, 10:39 AM
If I can remember correctly if the thread returns you do not need to call the end function. If the thread runs forever or you just need to end it the end function has to be called from within the thread so the best thing to do is send that thread a message telling it to kill itself. Hope this helps. P.S. there are several ways to send this message using a global class is one.

Kailash Marthi
December 1st, 1999, 10:41 AM
You can cast the unsigned long returned by _beginthreadex() and what you get is a HANDLE. You can then use it in _endthreadex().


HANDLE hThread = (HANDLE)_beginthreadex(...);

_endthreadex(hThread);