多线程的测试

 全局:
CEvent g_event;
UINT MyThreadProc(LPVOID pParam);

OnInitDialog()中:
AfxBeginThread((AFX_THREADPROC)MyThreadProc,(LPVOID)this);


UINT MyThreadProc(LPVOID pParam)
{
 ATLTRACE("thread start/n");

 CGraphofData* ptdlg=(CGraphofData*)pParam;
 while(1)
 {
  ATLTRACE("等待信号:/n");
  WaitForSingleObject(g_event.m_hObject,INFINITE);
  //ptdlg->AddData2Oscilloscope(3,0);
  ATLTRACE("有信号/n");
  ATLTRACE("get_filedata.size()=%d/n",get_filedata.size());
  for(int i=0;i<get_filedata.size();i++)
  {
   ATLTRACE("i=%d,delaytime=%d,data=%d/n",i,get_filedata[i].delaytime,get_filedata[i].data);
   Sleep(get_filedata[i].delaytime);
   ptdlg->AddData2Oscilloscope(get_filedata[i].band,get_filedata[i].data);
  }
  
 }
 ATLTRACE("thread end/n");
 return 0;
}

在需要调用线程函数时设置有信号,即:
g_event.SetEvent();

你可能感兴趣的:(多线程的测试)