what is the proper way of passing a C++ object (a map, vector, etc.) from one thread to another? I fear race conditions, stale values, etc. I am using boost threads.
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This depends solely of what this object “does”. If it’s self-contained, i.e. doesn’t hold pointers/references to other objects that may be used in the originating thread – there seems to be no problem. If OTOH it does contain references to some data that still may be in use in the originating thread – its access should be synchronized.
And, of course, passing a complex object by-value should be avoided.