向大家请教一个关于多线程互斥的问题,望不吝赐教,十分感谢!
DWORD WINAPI ThreadProc18(LPVOID pthread) {
while(1)
{
WaitForSingleObject(hMutex,INFINITE);
for (int i=0;i<10;i++)
{
CWnd * pWnd;
pWnd =CWnd::FindWindow ( NULL, "UDP_test" );//UDP_test为对话框标题
CString str;
str.Format("%d",i);
pWnd->SetDlgItemText(IDC_EDIT1_xiancheng2,str);
Sleep(100);
}
global_count++;
ReleaseMutex(hMutex);
}
}
DWORD WINAPI ThreadProc19(LPVOID pthread)
{
while(1)
{
WaitForSingleObject(hMutex,INFINITE);
for (int i=0;i<10;i++)
{
CWnd * pWnd;
pWnd =CWnd::FindWindow ( NULL, "UDP_test" );//UDP_test为对话框标题
CString str;
str.Format("%d",i);
pWnd->SetDlgItemText(IDC_EDIT1_xiancheng,str);
Sleep(100);
}
global_count++;
ReleaseMutex(hMutex);
}
}
程序中还使用了WSAAsyncSelect(m_socket_net,m_hWnd,UM_SOCK,FD_READ),socket UDP通信,在
case FD_READ:
...
WaitForSingleObject(hMutex,INFINITE);
global_count++;
ReleaseMutex(hMutex);
break;
程序运行后,上面的两个线程工作正常,交替增加并显示,但是当接收到网络数据时,程序停在case FD_READ的WaitForSingleObject(hMutex,INFINITE);处,所有线程停止,程序死了,请问是怎么回事?十分感谢!