【问题标题】:C++ barrier function cannot be assign (windows)C++ 屏障函数不能赋值(windows)
【发布时间】:2021-06-04 23:49:57
【问题描述】:

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

任何建议如何解决它?让它工作?

通过 std::thread 重写解决

【问题讨论】:

    标签: c++ windows barrier


    【解决方案1】:

    请注意,当您将lpParam 转换为dectectorData* 时,您应该像这样进行转换:(detectorData*)lpParam 而不是(detectorData)lpParam。 (注意 * 表示一个指针。)

    【讨论】:

    • 非常感谢 O:)
    【解决方案2】:

    由于我使用的是 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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 2012-06-16
      • 2013-04-19
      • 1970-01-01
      • 2014-09-18
      • 2011-01-04
      • 1970-01-01
      相关资源
      最近更新 更多