0

I use this example for circular buffering.

To test test I created next three functions:

void cnt(ScreenStreamer &SS, cv::Mat & img)
{
    CVUtils::Image m_img;
    SS >> m_img;
    img = m_img.matRef();
    cv::imshow("",img);
    cv::waitKey();
}

void  snd1(circ_buffer<cv::Mat  > & CM,  cv::Mat &  M)
{
    CM.send(M);

}
void rcv1(circ_buffer<cv::Mat > & CV, cv::Mat  & M)
{
    M = CV.receive();
}

And then run it in main function:

int main()
{
    ScreenStreamer stream;
    CVUtils::Image m_img;
    cv::Mat bufImg;
    cv::Mat inpImg;
    int key = 0;
    circ_buffer<cv::Mat > F1;
    F1.set_capacity(50);

    std::thread m1( snd1, F1, &inpImg );
    std::thread m2( rcv1, F1, &bufImg );
    std::thread m3( cnt, stream, &inpImg);

    m1.join();
    m2.join();
    m3.join();
    return 0;
}

Unfortunatelly I get this error

Error   C2664   'std::tuple<void (__cdecl *)(circ_buffer<cv::Mat> &,cv::Mat &),circ_buffer<cv::Mat>,cv::Mat *>::tuple(std::tuple<void (__cdecl *)(circ_buffer<cv::Mat> &,cv::Mat &),circ_buffer<cv::Mat>,cv::Mat *> &&)': cannot convert argument 1 from 'void (__cdecl &)(circ_buffer<cv::Mat> &,cv::Mat &)' to 'std::allocator_arg_t' CVUtilsExperimental C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory   1630

Does it come from template implementation or from function implementations? What to google to solve it?

hagor
  • 304
  • 1
  • 15

1 Answers1

0

All your functions take parameters by reference, you need to use std::ref wrapper class to pass them to thread constructor:

The arguments to the thread function are moved or copied by value. If a reference argument needs to be passed to the thread function, it has to be wrapped (e.g. with std::ref or std::cref). thread reference

so rewrite as follows

std::thread m1( snd1, ref(F1), ref(inpImg) );
std::thread m2( rcv1, ref(F1), ref(bufImg) );
std::thread m3( cnt, ref(stream), ref(inpImg) );
rafix07
  • 20,001
  • 3
  • 20
  • 33