ajl123
ajl123

Reputation: 1272

Visual Studio13 Creating Threads and Optimizing Process

I am writing multiple threads in VS13

Function declarations:

void getColorImage(HANDLE &colorEvent, HANDLE &colorStreamHandle, Mat &colorImage);
void getDepthImage(HANDLE &depthEvent, HANDLE &depthStreamHandle, Mat &depthImage);
void getSkeletonImage(HANDLE &skeletonEvent, Mat &skeletonImage, Mat &colorImage, Mat &depthImage, ofstream& myfile);

int main()
{
    // this is inside a while loop

    std::thread first(getColorImage, colorEvent, colorStreamHandle, colorImage);
    std::thread second(getDepthImage, depthEvent, depthStreamHandle, depthImage);
    std::thread third(getSkeletonImage, skeletonEvent, skeletonImage, colorImage, depthImage, myfile);

    first.join();
    second.join();
    third.join();
 }

However, I get an error:

Error 1 error C2280: 'std::basic_ofstream>::basic_ofstream(const std::basic_ofstream> &)' : attempting to reference a deleted function c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits 1545 1 Skeleton_RGBDepth_DataAcquisition2013

Don't know why... can someone please help?

Upvotes: 0

Views: 160

Answers (1)

Siyuan Ren
Siyuan Ren

Reputation: 7844

std::thread constructor, the same as std::bind, takes all its parameters by value. But std::ofstream have a deleted copy constructor, hence the error.

Wrap all parameters that should be passed by reference with std::ref.

Upvotes: 1

Related Questions