|
如题,使用了queue,2个线程一个push,一个pop。使用了互斥量。但是程序运行中
会随机在push的时候出错,而且出错时间比较快。经过调试,发现应该是在queue push
分配内存的时候出错了。
我的pop与push函数代码如下:
Pop函数:
void MsgProcRun()
{
DWORD dwWaitResult = WaitForSingleObject( hMutex, 100L);
if( dwWaitResult == WAIT_OBJECT_0 )
{
if( !MsgStack->isEmpty() )
{
DXInput::MsgStackNode MsgNode = MsgStack-> op();
MsgProc( MsgNode );
}
ReleaseMutex(hMutex);
}
}
Push函数:
int MsgPro( DXInput::StackCellForMessageAndType MsgNode )
{
DWORD dwWaitResult = WaitForSingleObject( hMutex, 100L);
if( dwWaitResult == WAIT_OBJECT_0 )
{
if( MsgStack == NULL ) return -1;
MsgStack->Push( MsgNode );
ReleaseMutex(hMutex);
}
return 1;
}
程序里面使用了一些自定义类型,包括queue稍微做了下封装。大家不用理会。请高手帮我看看问题出在哪里啊? |
|