具有非空函数的多线程
Multi threading with non-void functions
我正在尝试在C++中多线程我的程序(我使用 OpenCV 库)这是代码:
double _find_eyes (Mat img, vector<Rect_<int> > & finalEyes)
{
//some code working on image
return valueOfMatch; //is a double
}
double _find_mouth (Mat img, vector<Rect_<int> > & finalMouth)
{
//some code working on image
return valueOfMatch; //is a double
}
double _find_face ()
{
eyesMatch = _find_eyes(image, eye);
mouthMatch = _find_mouth(image, mouth);
totalMatch = eyesMatch + mouthMatch;
}
int main()
{
find_face();
}
我想用线平行地找到嘴巴和眼睛。怎么办?我的问题在于非空函数和返回值。提前谢谢。
一个简单的方法是使用 std::async
,例如:
double _find_face ()
{
auto eyesMatch = std::async(std::launch::async, _find_eyes, std::ref(image), std::ref(eye));
auto mouthMatch = std::async(std::launch::async, _find_mouth, std::ref(image), std::ref(mouth));
return eyesMatch.get() + mouthMatch.get();
}
相关文章:
- 如何正确取消析构函数中的 Boost deadline_timer(在多线程环境中)?
- 如何在大函数中编写多线程函数?
- 将数组作为多线程应用程序中函数的返回传递
- 在多线程函数中返回共享的常量指针会导致计时问题吗?
- 是否可以多线程同时执行非空函数?(C++)
- 具有多线程支持的 RenderClass,将函数调用推送到向量以在另一个线程上调用
- 对象析构函数在多线程处理时不断被调用,但该对象并未超出范围
- gdb:在多线程程序中调用函数,不进行线程
- C++函数中的多线程静态 POD 初始化
- C++多线程程序尝试使用已删除的函数
- C++多线程在函数调用期间避免交错
- 如何在多线程 MEX 函数中打印到控制台?
- TBB C++多线程错误:没有匹配的调用函数
- 在多线程中调用带有输入参数的函数
- 多线程 C++ 将参数传递给函数
- 在多线程处理时将参数传递给函数
- 从多线程C++插件回调NodeJS Javascript函数
- 通过引用使用参数进行 C++ 多线程函数调用
- 将单个整数传递给c++中的多线程函数
- C++多线程函数在Linux和Windows中具有包容性和排他性