boost::thread Destructor being called multiple times
I was just curious as to why the class destructor are (apparently)
being called multiple times. I have tried searching the archives to no
avail (which prompted me to register and post to the mailinglist).
#include
kaliwanagan wrote:
I was just curious as to why the class destructor are (apparently) being called multiple times. >
[...]
I would appreciate if someone can enlighten me on this. Will having the destructor called multiple times be a cause of concern? Will it cause some undefined symptoms? Is there a way to completely avoid this situation?
The multiple callings on destructor are not on same object. If you add a copy constructor, TestingClass(const TestingClass &) { std::cout << "constructor called" << std::endl; } you will see the constructor being called same times. You can use Boost.Bind to avoid multiple object-copying. struct TestingClass { ... void run() { std::cout << "run() called" << std::endl; } ... } ... void testBoostThread() { boost::thread thrd(boost::bind(&TestingClass::run, &testclass)); thrd.join(); }
Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von kaliwanagan Gesendet: Samstag, 25. August 2007 15:52 An: boost-users@lists.boost.org Betreff: [Boost-users] boost::thread Destructor being called multiple times
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Boost::thread passes its function object around several times by value, so it gets coyp-constructed and destructed several times. I had the same problem, and used some sort of proxy-class until I realized that boost::bind creates exactly that kind of proxy-objects. So either use boost::bind or boost::mem_fn or std::mem_fun. Best Regards Markus
Hi
I m using multiarray to stores edges of an graph. I m reading the data
from a csv file.
My line is L1,0,0,0,1
Now i m using stringtok and storing the values
typedef boost::multi_array
Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von kaliwanagan Gesendet: Samstag, 25. August 2007 15:52 An: boost-users@lists.boost.org Betreff: [Boost-users] boost::thread Destructor being called multiple times
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Boost::thread passes its function object around several times by value, so it gets coyp-constructed and destructed several times. I had the same problem, and used some sort of proxy-class until I realized that boost::bind creates exactly that kind of proxy-objects. So either use boost::bind or boost::mem_fn or std::mem_fun.
Best Regards Markus _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
ForwardSourceID:NT0004890A =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you
participants (4)
-
Abhishek V
-
gchen
-
kaliwanagan
-
KLINIK Markus STD2-G (AREVA NP GmbH)