使用ace_barrier出现异常
我用vc6.0写了一个程序,通过ace_barrier同步线程。方式是在一个线程中新建一个ace_barrier实例,然后新建一个线程,把实例的指针作为参数传到线程,在两个线程中通过ace_barrier.wait()同步线程,可是在有的时候会出现异常,附件是调试时的信息,请高手帮忙看看。 你只搞了两张图片上来,也不知道你说什么问题啊。 CCriticalSection g_WriteLogLock;//用于调用信息的线程函数
UINT ModuleFunc(LPVOID a_pThreadInfo)
{
char* pDataRcvBuffer=NULL;
try
{
STThreadInfo* pThreadInfo = (STThreadInfo*)a_pThreadInfo;
ACE_Barrier* pDataCopyBarrier = pThreadInfo->m_pBarrier;
CString sModuleName = pThreadInfo->m_sModuleName;
UINT nMsgUserDefined = pThreadInfo->m_nMsgDefined;
UINT nClientID = pThreadInfo->m_nClientID;
LPVOID pClientStream = pThreadInfo->m_pStream;
_bstr_t strCon = pThreadInfo->m_strCon;
LPVOID SendDataFunc = pThreadInfo->m_pFunc;
LPCSTR sDataSeries = pThreadInfo->m_pData;
UINT nDataSeriesAmount = pThreadInfo->m_nDataLen;
pDataRcvBuffer = new char;
memcpy(pDataRcvBuffer, sDataSeries, nDataSeriesAmount);
pDataCopyBarrier->wait();
//载入模块
HINSTANCE hInst;
hInst = LoadLibrary(sModuleName);
typedef (*ACCEPTDATAPROC) (UINT a_nCmdID, LPCSTR a_sDataSeries, UINT a_nDataSeriesAmount, UINT a_nClientID, LPVOID a_cClientAddr,_bstr_t a_strCon, LPVOID a_SendDataFunc);
ACCEPTDATAPROC AcceptData = (ACCEPTDATAPROC)GetProcAddress(hInst,"AcceptData");
//调用模块函数
if (AcceptData)
{
AcceptData(nMsgUserDefined, (LPCSTR)pDataRcvBuffer, nDataSeriesAmount, nClientID, pClientStream, strCon, SendDataFunc);
}
FreeLibrary(hInst);
}
catch(...)
{
g_WriteLogLock.Lock();
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("ModuleFunc"),_T(""),_T("线程同步异常或载入模块异常"));
g_WriteLogLock.Unlock();
if(pDataRcvBuffer != NULL)
{
delete[] pDataRcvBuffer;
}
return 1;
}
if(pDataRcvBuffer != NULL)
{
delete[] pDataRcvBuffer;
}
return 0;
}
// 数据处理回调函数的执行部分
int WINAPI CDataHandler::DataHandleFunc(UINT a_nClientID,
UINT a_nMsgUserDefined, LPCSTR a_sDataSeries,
UINT a_nDataSeriesAmount, LPVOID a_pClientStream)
{
ACE_Barrier DataCopyBarrier(2);
CString sModuleName;
try
{
std::map<int, CString>::iterator iter;
iter = m_pDataHandler->m_mapModule.find(a_nMsgUserDefined);
sModuleName.Format("%s",iter->second);
}
catch(...)
{
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("DataHandleFun"),_T(""),_T("在map中寻找模块异常"));
}
try
{
STThreadInfo* pThreadInfo = new STThreadInfo;
pThreadInfo->m_pBarrier = &DataCopyBarrier;
pThreadInfo->m_sModuleName = sModuleName;
pThreadInfo->m_nMsgDefined = a_nMsgUserDefined;
pThreadInfo->m_nClientID = a_nClientID;
pThreadInfo->m_pStream = a_pClientStream;
pThreadInfo->m_strCon = (m_pDataHandler->m_DataProcess).m_strCon;
pThreadInfo->m_pFunc = SendDataFunc;
pThreadInfo->m_pData = a_sDataSeries;
pThreadInfo->m_nDataLen = a_nDataSeriesAmount;
// ACEProxy开始工作
CWinThread* pThreadStartUp;
pThreadStartUp = AfxBeginThread(ModuleFunc, (LPVOID)pThreadInfo,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThreadStartUp->ResumeThread();
// CloseHandle(pThreadStartUp->m_hThread);
DataCopyBarrier.wait();
}
catch(...)
{
g_WriteLogLock.Lock();
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("DataHandleFun"),_T(""),_T("载入DLL模块异常"));
g_WriteLogLock.Unlock();
}
return 0;
} 上面是代码,调试的时候发现出现问题的时候,ModuleFunc()里面的ace_barrier指针(pDataCopyBarrier)指向的内容有问题,类的变量都是乱的,pDataCopyBarrier 的值是正确的,不知道是:) ataHandleFunc里面DataCopyBarrier实例化的时候失败,还是这个函数出现异常,希望 winston 能给个调试的方法,怎么判断ace_barrier的状态?ace_barrier.dump()怎么用? 在ModuleFunc载入的dll后,dll的函数可能会产生内存泄露,STThreadInfo* pThreadInfo = new STThreadInfo new出来以后没有删除,错误可能是这个原因导致的吗?
页:
[1]