문제

I'm trying to use thread_group from the boost libraries to manipulate matrix objects from the openCV libraries (the program is written in C++). However when I try to save the matrices after joining the main thread again, the matrix doesn't contain any data. Can anyone provide an example how to manipulate matrices using boost thread_group ? (I really need multithreading, since the computation takes days otherwise)

Here is the code I'm using so far:

Mat myMatrix;
// Start threads
boost::thread_group threadGroup;
threadGroup.create_thread(boost::bind(&manipulateMatrixFunction,myMatrix));
threadGroup.join_all();

The matrix is only declared in the main thread. The initialisation with number of rows, cols and datatype takes place inside "manipulateMatrixFunction". (Maybe that is part of the problem?)

올바른 솔루션이 없습니다

다른 팁

Pass the Mat instance by reference:

#include <boost/ref.hpp>

//...
threadGroup.create_thread(boost::bind(&manipulateMatrixFunction,boost::ref(myMatrix)));
//...

But make sure that this instance outlives the thread.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top