I have a very simple question about how CWinThread works and where is the entry point everytime I called ResumeThread(). I’m looking for an entry that looks similar as “main” function where I can perform some operations and branches.
I’m also wondering how to end or kill running threads at any point from different thread. Where should I put AfxEndThread()? or simply call pThread->ExitInstance()?
My last question is, if i want to make multiple threads, how do I organize them in Standard Template Library (STL) using vector?
Thank you.
The primary entry point for a class derived from
CWinThreadis the virtualRun()function. However, there is also anInitInstance()function which is called beforehand, and anExitInstance()function called afterwards.You should never call
ExitInstance()yourself. Instead, callAfxEndThread, or just return fromRun().If you really want to put your threads in a
std::vector<>then use a pointer as the class is not copyable, and the instance is deleted automatically by MFC when the thread exits.Edit: As David pointed out, you generally don’t want to use
SuspendThreadandResumeThreadin application code. Start your thread withAfxBeginThreadif you’re using MFC.