コード例 #1
0
ファイル: ifc_thread.cpp プロジェクト: haoxingeng/ifc
//-----------------------------------------------------------------------------
// 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(); );