Boost logo

Boost Users :

From: Marshall Clow (marshall_at_[hidden])
Date: 2008-02-11 13:31:31


At 10:59 AM -0700 2/11/08, Hector C wrote:
>Hello fellow boost fans,
>
>Could anyone explain to me why the destructor (in the program listed
>below) seems to be called 10 times but the constructor only one time?
>The output of the program is also shown below.

I think that adding a copy constructor and/or an assignment operator
to your sample will help with your enlightenment. ;-)

>--- BEGIN PROGRAM ---
>#include <boost/thread/thread.hpp>
>#include <iostream>
>
>using namespace std;
>
>struct ThreadBug
>{
> ThreadBug()
> {
> cout << "Begin sending ... " << endl;
> }
>
> ~ThreadBug()
> {
> cout << "End sending ... " << endl;
> }

       ThreadBug ( const ThreadBug &rhs ) { cout << "Copy constructing
... " << endl; }
       ThreadBug & operator = ( const ThreadBug &rhs ) { cout <<
"Assigning ... " << endl; return *this; }

> void operator()()
> {
> cout << "Do something ... " << endl;
> }
>} w_ThreadBug;
>
>int main()
>{
> cout << "New Sequence -----------" << endl;
> boost::thread thrd(w_ThreadBug);
> thrd.join();
> cout << "End New Sequence -----------" << endl;
> return 0;
>}
>---END PROGRAM ---

-- 
-- Marshall
Marshall Clow     Idio Software   <mailto:marshall_at_[hidden]>
It is by caffeine alone I set my mind in motion.
It is by the beans of Java that thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net