C++ 屏障函数不能被赋值windows

问题描述

我想创建一些像 void Function(struct str) 这样简单的东西来计算障碍同步中的并行,但似乎没有那么简单,所以我遵循了这个: https://docs.microsoft.com/en-us/windows/win32/procthread/creating-threads 和其他一些主题,但没有成功。找不到解决办法。代码全部在一个文件中。

任何建议如何修复它?让它发挥作用?

通过 std::thread 重写解决

Printscreened code,due to unknow issue putting in here... -_-

解决方法

注意当您将 lpParam 转换为 dectectorData* 时您应该如何转换:(detectorData*)lpParam 而不是 (detectorData)lpParam。 (注意 * 表示指针。)

,

因为我使用的是 C++,所以已经有了 std::thread 类。 所以我的简单任务可以通过这段代码完成:

void detAndComputeT(detectorData &data) {
Ptr<SIFT> detector = cv::SIFT::create();
detector->detectAndCompute(data.image,Mat(),data.keypoints,data.descriptors);
}

std::thread threads2[2];
detectorData dataImage1;
detectorData dataImage2;
dataImage1.image = image1_toCalc;
dataImage2.image = image2_toCalc;
threads2[0] = thread(detAndComputeT,std::ref(dataImage1));
threads2[1] = thread(detAndComputeT,std::ref(dataImage2));
threads2[0].join();
threads2[1].join();