i should lock that too? but those threads are somewhere else ! only main thread is doing the assignment!
a) the main thread modifies "threadarray" object; b) the other threads read "threadarray" object (technically speaking, they might modify it as well because of vector's operator[] nature). You should synchronize (a) and (b) - using mutex.
would locking pause all these threads ?
It will pause, if you do as follows: int main() { lock_guard<mutex> lock(mutex); threadarray[0] = boost::thread(t,5); threadarray[1] = boost::thread(t,6); threadarray[2] = boost::thread(t,7); lock.unlock(); //... } int t(int x) { lock_guard<mutex> lock(mutex); // access threadarray lock.unlock() //... } This way the thread function t() accesses threadarray only after it's filled in main().
and what do you mean by :
// copy id objects here to some local array whats your meaning about id objects ?
thread::get_id() and this_thread::get_id() return you thread::id instances: http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#...
whats the local array ? an array declared inside that function ?
Yes.
(would be shared among other threads too right?
No. Local objects are not shared between threads.