You could do the operations below:
- add the
CREATE_SUSPENDED
flag to any call to AfxBeginThread
- call
DuplicateHandle
to get a copy of the m_hThread
of each CWinThread
object returned by the previous call to AfxBeginThread
- call
ResumeThread
on each CWinThread
object returned by the previous call to AfxBeginThread
This will ensure that you get an handle to each thread you create (you should create each thread suspended because
CWinThread
will auto-delete on thread termination, and you need that the thread doesn't terminate before that you have completed your initialization steps).
When you are about to terminate your main thread, do the following:
- make a call to
WaitForMultipleObject
passing it an array with all the handles of the threads you have created - call
CloseHandle
fore each handle that you have previously duplicated