At the end of this message is a test program that uses boost::thread
to create two threads. The first is one that takes a parameter by
value, the second takes a parameter by reference. I have a couple of
questions about some behavior here:
1) When passing by value, why are so many copies of the data made? The
program output indicates that there are 9 (!) objects created (at most
5 exist simultaneously), when ideally there would be only 2 (the
original and the copy passed to the thread).
2) When passing by reference, why is the data being copied? The
copying behavior when passed by reference is identical to when the
param is passed by value (9 objects created, 5 simultaneously). Also,
and this isn't shown in the program below, but I would therefore
expect the program to crash if the boost::thread outlived the
referenced object (of course, it does not, since the object is
copied).
So, I'm surprised by the number of copies, this seems unreasonable,
and also I'm confused about why by value and by reference behave
identically.
Thanks,
Jason
=== BEGIN EXAMPLE ===
#include