Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 英特尔TBB是否在并行线程中运行函数?_C++_Multithreading_Opencv_Tbb - Fatal编程技术网

C++ 英特尔TBB是否在并行线程中运行函数?

C++ 英特尔TBB是否在并行线程中运行函数?,c++,multithreading,opencv,tbb,C++,Multithreading,Opencv,Tbb,基本上,我正在开发一个opencv应用程序。我已经用cmake中的_tbb选项构建了OpenCV 我想使用intel tbb运行一个并行线程,该线程每隔一段时间更新一些全局变量。比如: vector<int> mySharedVar; void secondaryThreadFunction() { while(true) { Do some operations And update mySharedVar if necessarily usleep(1

基本上,我正在开发一个opencv应用程序。我已经用
cmake
中的_tbb选项构建了OpenCV

我想使用intel tbb运行一个并行线程,该线程每隔一段时间更新一些全局变量。比如:

vector<int> mySharedVar;

void secondaryThreadFunction() {
 while(true) {
   Do some operations
   And update mySharedVar if necessarily  

   usleep(1000);
 }
}

int main() {
   run in parallel secondaryThreadFunction;

   in the master Thread keep doing something based on mySharedVar

   while(true) {
    do something;
   }
}
vector mySharedVar;
void secondaryThreadFunction(){
while(true){
做一些手术
并在必要时更新mySharedVar
usleep(1000);
}
}
int main(){
并行运行secondaryThreadFunction;
在主线程中,继续基于mySharedVar执行某些操作
while(true){
做点什么;
}
}

如何在另一个线程上运行
secondaryThreadFunction()

英特尔TBB不适用于这种用途。 引自:

“英特尔线程构建块”以线程性能为目标。 大多数通用线程包支持多种不同类型的线程 线程的定义,例如图形系统中异步事件的线程 用户界面。因此,通用软件包往往是 低级工具提供了基础,而不是解决方案。相反 英特尔®线程构建块专注于以下特定目标: 并行计算密集型工作,提供更高级别的, 更简单的解决方案

通过
boost::thread
或C++11线程功能,您可以轻松完成想要完成的任务:

   // using async
   auto fut = std::async(std::launch::async, secondaryThreadFunction);
   // using threads (for boost, just replace std with boost)
   std::thread async_thread(secondaryThreadFunction);

   in the master Thread keep doing something based on mySharedVar

   while(true) {
    do something;
   }

   // in case of using threads
   async_thread.join();

请记住,同步对任何共享变量的访问。

英特尔TBB不适用于这种用途。 引自:

“英特尔线程构建块”以线程性能为目标。 大多数通用线程包支持多种不同类型的线程 线程的定义,例如图形系统中异步事件的线程 用户界面。因此,通用软件包往往是 低级工具提供了基础,而不是解决方案。相反 英特尔®线程构建块专注于以下特定目标: 并行计算密集型工作,提供更高级别的, 更简单的解决方案

通过
boost::thread
或C++11线程功能,您可以轻松完成想要完成的任务:

   // using async
   auto fut = std::async(std::launch::async, secondaryThreadFunction);
   // using threads (for boost, just replace std with boost)
   std::thread async_thread(secondaryThreadFunction);

   in the master Thread keep doing something based on mySharedVar

   while(true) {
    do something;
   }

   // in case of using threads
   async_thread.join();
请记住同步对任何共享变量的访问