Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// The thread execution procedure.
// Parameters:
//   pParam: Points to the CThread object.
//-----------------------------------------------------------------------------
UINT __stdcall ThreadExecProc(LPVOID pParam)
{
	CThread *pThread = (CThread*)pParam;
	int nReturnValue = 0;

	if (!pThread->m_bTerminated)
	{
		struct CAutoFinalizer
		{
			CThread *m_pThread;
			CAutoFinalizer(CThread *pThread) { m_pThread = pThread; }
			~CAutoFinalizer()
			{
				m_pThread->m_bFinished = true;
				if (m_pThread->GetFreeOnTerminate())
					delete m_pThread;
				else
					m_pThread->m_nThreadId = 0;
			}
		} AutoFinalizer(pThread);

		CATCH_ALL_EXCEPTION( pThread->Execute(); );
		CATCH_ALL_EXCEPTION( pThread->AfterExecute(); );