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?

2
  • 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 Commented Oct 11, 2012 at 17:40
  • the one in tbb\compat is I believe movable, however he is using vs2008 which doesn't have rvalue support. Commented Oct 11, 2012 at 22:06

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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::threads

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.