C++线程之间的通信问题。 5
现在编写了两个线程,希望通过子线程的SetEvent函数与主线程通信,主线程中用WaitForSingleObject函数来接收信息。调试时候发现程序的执行顺序似乎跟预想...
现在编写了两个线程,希望通过子线程的SetEvent函数与主线程通信,主线程中用WaitForSingleObject函数来接收信息。调试时候发现程序的执行顺序似乎跟预想的不一样。下面是相关代码,请给位高手帮帮忙,该使用另外的函数么?
主线程:
for(int i = 0; i<12;i++)
{
_beginthread(Grab, 0, NULL );
WaitForSingleObject(startgrab,INFINITE);
{
MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, M_START + M_FRAMES_PER_TRIGGER(1), M_ASYNCHRONOUS + M_TRIGGER_FOR_FIRST_GRAB , ProcessingFunction, &UserHookData);
i++;
}
}
子线程
void Grab(void *)
{
//Send software trigger signal
MdigControl(MilDigitizer, M_TIMER1 + M_GRAB_EXPOSURE, M_ACTIVATE);
SetEvent(startgrab);
Sleep(200);
_endthread();
} 展开
主线程:
for(int i = 0; i<12;i++)
{
_beginthread(Grab, 0, NULL );
WaitForSingleObject(startgrab,INFINITE);
{
MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, M_START + M_FRAMES_PER_TRIGGER(1), M_ASYNCHRONOUS + M_TRIGGER_FOR_FIRST_GRAB , ProcessingFunction, &UserHookData);
i++;
}
}
子线程
void Grab(void *)
{
//Send software trigger signal
MdigControl(MilDigitizer, M_TIMER1 + M_GRAB_EXPOSURE, M_ACTIVATE);
SetEvent(startgrab);
Sleep(200);
_endthread();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询