Gracefull thread killing when App ends
Posted on 1998-11-19
My app will sometimes create a CWinThread-derived thread to go do some work. It is technically a UI thread, since it has a window, used to monitor what is going on, but it does not get any user input.
I have the thread set up with the m_bAutoDelete to TRUE, so that once the tread is finished it deletes itself. This works quite well until I try quitting the program while the thread is still running. When this happens the thread gets killed, and memory leaks abound.
So I thought, when the app is quitting, I could somehow inform the thread that it is time to die. However, because the thread can destroy itself, I don't know if I have a thread still running or not. The thread destroys itself, but my pointer still has a value, alas one that is useless.
How can I figure out if the thread is still running when I quit, and if so tell it to quit before the app finishes?