Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can i kill a thread from the main thread that created it?

kill main thread
0
Posted

Can i kill a thread from the main thread that created it?

0

>can i kill a thread from the main thread that created it? >under Windows, i only found the CWinThread::ExitInstance () method, You can kill a thread with TerminateThread(). Using TerminateThread is really, really, really, really, not recommended. If thread owns a critical section the critical section is not released and it will forever be unaccessable. If other threads then try to enter it they will hang forever. Also, the stack allocated to the thread is not released and various other bad things can happen. If you think you need to use TerminateThread it’s a good sign that your threading design is broken. You should be telling the thread to exit itself. Figuring out how to call TerminateThread using MFC’isms such as CWinThread is left as an exercise to the reader. -Mike > Also, the stack allocated to the thread is not released > and various other bad things can happen. Yes, it’s that bad… A while ago I started writing an app that used TerminateThread() – it leaked about a megabyte

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123