What is the correct way to pass a C ++ object from one thread to another using boost :: thread?

What is the correct way to pass a C ++ object (map, vector, etc.) from one thread to another? I'm afraid of race conditions, deprecated values, etc. I am using boost streams.

Thanks in advance!

+3


source to share


1 answer


It depends solely on what the object is "doing". If it is self-contained, that is, it does not contain pointers / references to other objects that might be used in the original stream - there seems to be no problem. If OTOH in contains links to some data that can still be used in the original stream, its access must be synchronized.



And of course, you should avoid passing a complex object by value.

+1


source







All Articles