我绝对是多线程和使用 OpenMP 的新手。但我正在尝试开发一个具有两个功能的程序。
function1(){
get the data from the camera and save it into memory for 1000fps
}
functio2(){
display and refresh the screen each 100ms
}
我认为 OpenMP 应该是这样的
#pragma omp sections
{
{ function1(); }
#pragma omp section
{ function2(); }
}
但我不确定如何在代码(c++)中实际实现它?如果有人知道,请告诉我。我最终得到了以下代码,但现在我想让第二部分每 100 毫秒休眠一次,我该怎么做?
lastPicNr = 0;
if(Fg_AcquireEx(fg,nCamPort,GRAB_INFINITE,ACQ_STANDARD,_memoryAllc)<0){
CExceptionHandler::GrabberErrorMessage(fg,"Can not start Acquiring images .");
}else{
//Declaring a parallel region that will be broken down into disctinct parallel sections
#pragma omp parallel sections
{
#pragma omp section
{
while((lastPicNr = Fg_getLastPicNumberBlockingEx(fg,lastPicNr+1,nCamPort,10,_memoryAllc))<= MaxPics){
iPtr=(unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc);
_PointVector.push_back(iPtr);
_lastPicNumber.push_back(lastPicNr);
}
}
#pragma omp section
{
cv::Mat _matrixImage(cv::Size(w,h), CV_8UC1,iPtr , cv::Mat::AUTO_STEP);
cv::imshow("test",_matrixImage);
cv::waitKey(10);
}
}
PauseClickMode(hDlg);
}