全局变量
HANDLE g_hThreadEvent;
void CMultiThread_MutexDlg::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码 theApp.g_hThreadEvent=CreateEvent(NULL,FALSE,FALSE,_T("ABC")); HANDLE handle[10]; for(int i=0;i<10;i++) { CWinThread *mythread=AfxBeginThread(ThreadFun_Tongbu,(LPVOID)&i); handle[i]=mythread->m_hThread; WaitForSingleObject(theApp.g_hThreadEvent,INFINITE); } WaitForMultipleObjects(10,handle,TRUE,INFINITE); CloseHandle(theApp.g_hThreadEvent); } UINT CMultiThread_MutexDlg::ThreadFun_Tongbu(LPVOID pParam) { int Num=*(int*)pParam; SetEvent(theApp.g_hThreadEvent); CString Result; Result.Format(_T("%d "),Num); OutputDebugString(Result); return 0; }