
Thanks for your meticulous observation :) so instead of just retyping lockguard inside all of if statements , one at the very beginning of the function in question would suffice right ? :)
Well, locking the whole thread function you actually prevent the threads from running in parallel. You could just lock the shared resource, copy it (if it's inexpensive), and release: lock_guard<mutex> locker(mutex); // copy id objects here to some local array locker.unlock(); // proceed.
int main() {
threadarray[0] = boost::thread(t,5); threadarray[1] = boost::thread(t,6); threadarray[2] = boost::thread(t,7);
You should lock the above as well, because when you're moving a thread object to threadarray, the thread function is already being runnning.