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.
i should lock that too? but those threads are somewhere else ! only main thread is doing the assignment! how would locking help main ? would locking pause all these threads ?
and what do you mean by :
whats your meaning about id objects ? did you mean the thread id ? , whats the local array ? an array declared inside that function ? (would be shared among other threads too right? then whats the point? )
Thank you again for your help sir :)