Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginthreadex() cleanup?

Status
Not open for further replies.

adiMasher

Programmer
Aug 31, 2001
144
US
Alright here's what I'm doing and I need to know if there are any dangers that I'm missing or even a better way of doing this.

Calling beginthreadex() for a checkkeystroke function that will call endthreadex(0) once a key is hit.
calling beginthreadex() again for another function that will listen on a udp port for incoming messages.

Then still in main call WaitForSingleObject( hThread, INFINITE ); to wait for the key press thread to come back

after that I'll just CloseHandle() both thread handles and exit main.

Now, I want to know that since I'm not using endthreadex on my second thread if it will cause some stack error or leave memory hangin and not being used and just sit there until a reboot.

any ideas, suggestions?

How can I end a thread outside of the actual thread function safely?

Thanks,
Martin I don't suffer from insanity.
I enjoy every minute of it.
 
If you take a look at VC98\CRT\SRC\THREADEX.C you'll find that _endthreadex() is called internally by _threadstarterex().

To make a clean thread stop from outside use an event (kernel object) for example. Its state (signalled or not signalled) you can check time to time with the WaitForSingleObject() with zero timeout. Best regards,

Igor mailto:igor_vartanov@mail.ru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top