Пример #1
0
UINT CThread::ThreadProc(LPVOID pObject)
{
	ASSERT(pObject);
	ASSERT_KINDOF(CThread, (CObject *)pObject);

	CThread *pThread = (CThread *)pObject;

	// initialisieren, ausführen, aufräumen
	if (pThread->InitInstance())
		pThread->Run();
	UINT nResult = pThread->ExitInstance();

	// den tatsächlich gelieferten Exit-Code setzen
	pThread->SetExitCode(nResult);

	pThread->m_pWinThread = NULL; // zerstört sich selbst
	HANDLE hThreadStoppedEvent = pThread->m_hThreadStoppedEvent;

	// Thread-Objekt ggf. automatisch zerstören
	if (pThread->m_bAutoDelete) delete pThread;

	// Beendigungs-Event setzen; setzt alle Threads fort, die in Join() warten
	VERIFY(SetEvent(hThreadStoppedEvent));

	return nResult;
}