0

I have a code like this:

    #include <iostream>
    #include <tbb/tbb.h>
    #include <Windows.h>



    bool MyThread(int something)
    {
        std::cout << "This is a thread function\n" << std::endl;

        for (int i = 0; i < 10000; i++)
        {
            something++;
            Sleep(1);
        }

        return true;
    }

    int main ()
    {
        tbb::tbb_thread pMyThread = tbb::tbb_thread(MyThread, 3);

        pMyThread.join();

        return 0;
    }

But if I compile it in VS 2008 it shows: error C2248: 'tbb::internal::tbb_thread_v3::tbb_thread_v3' : cannot access private member declared in class 'tbb::internal::tbb_thread_v3'

for the first string of main() function. Where am I wrong?

Nabijon
  • 821
  • 2
  • 13
  • 17
  • Most thread objects, either tbb or c++11 cannot be copied or assigned. You code invoke an unnecessary assignment operator which is private to prevent you do exactly this. However C++11 thread are movable. Not sure if it is the case of tbb – Yan Zhou Oct 11 '12 at 17:40
  • the one in tbb\compat is I believe movable, however he is using vs2008 which doesn't have rvalue support. – Rick Oct 11 '12 at 22:06

1 Answers1

3

This is likely calling a copy constructor when it shouldn't, try this instead:

tbb::tbb_thread myThread(MyThread, 3); 

If you are able you should also consider using std::thread which is in the header

Rick
  • 3,285
  • 17
  • 17
  • Why using `std::thread` if question is TBB related? I'm evaluating TBB for performance purposes and I'm curious about benchmarking it against `std::thread`s – Patrizio Bertoni Mar 10 '16 at 13:42