I'm trying to create threads to run row-by-row on a grid-based terrain (i'm not asking if this is efficient, I'm just testing something out) but I keep coming across 2 errors:
first being that if I don't pass the function as
&DJM::Terrain:GenBlocks
The compiler tells me to append the & at the start but when I do use the reference it gives me a seperate error connected to xmemory
error C2248: 'std::thread::thread' : cannot access private member declared in class 'std::thread'
1> d:\program files\visual studio 2012\vc\include\thread(73) : see declaration of 'std::thread::thread'
1> d:\program files\visual studio 2012\vc\include\thread(32) : see declaration of 'std::thread'
and I seriously do not understand why. I've read in multiple places that you should put this as the 2nd argument but that gives exactly the same error as above. I have also tried passing i as an std::ref but that gives the same error.
for(size_t i = 0; i < mHEIGHT; ++i){
std::thread t(&DJM::Terrain::GenBlocks, &i);
mThreads.push_back(t);
}
for(std::vector<std::thread>::iterator iter = mThreads.begin(); iter != mThreads.end(); iter++){
iter->join();
}
Quite a large code file so I'd rather not post the entirety of the class but if there's no immediate errors with the code I've posted I'd be happy to post the rest of the code. Note that mThreads is stored as a member variable.
std::thread
s cannot be copied. Move it into the vector:
mThreads.push_back(std::move(t));