Question

I am working with OpenCV, an open source image processing library, and due to complexities in my algorithm I need to use multiple threads for video processing.

How multi-threading is done on C++ 98? I know about C++ 11 has a built in support library for threading (std::thread) but my platform (MSVC++ 2010) does not have that. Also I read about Boost library, which is a general purpose extension to C++ STL, has methods for multi-threading. I also know with MSDN support (windows.h) I can create and manage threads for Windows applications. Finally, I found out that Qt library, a cross platform GUI solution, has support for threading.

Is there a naive way (not having any 3rd party libraries) to create a cross-platform multi-threading application?

Was it helpful?

Solution 2

OpenCV relies on different external systems for multithreading (or more accurately parallel processing). Possible options are:

  • OpenMP (handled at the compiler level);
  • Intel's TBB (external library);
  • libdispatch (on systems that support it, like MacOS, iOS, *BSD);
  • GPGPU approaches with CUDA and OpenCL.

In recent versions of OpenCV these systems are "hidden" behind a parallel_for construct.

All this applies to parallel processing, i.e., data parallel tasks (roughly speaking, process each pixel or row of the input in parallel). If you need application level multithreading (like for example having a master thread and workers) then you need to use frameworks such as POSIX's threads or Qt.

OTHER TIPS

C++98 does not have any support for threading, neither in the language nor the standard library. You need to use a third party library and you have already listed a number of the main candidates.

I recommend boost::thread which is (mostly) compatible with std::thread in C++11. It is cross-platform and very mature.
OpenCV's parallelism is internal and does not directly mix with your code, but it may use more resources and cores than you might expect (as a feature), but this might be at the expense of other external processes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top