Boost logo

Boost Users :

From: Hector C (forgotoldaddress_at_[hidden])
Date: 2008-02-11 12:59:40


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.

Cheers,

Hector C.

--- BEGIN PROGRAM ---
#include <boost/thread/thread.hpp>
#include <iostream>

using namespace std;

struct ThreadBug
{
     ThreadBug()
     {
         cout << "Begin sending ... " << endl;
     }

     ~ThreadBug()
     {
         cout << "End sending ... " << endl;
     }

     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 ---

Begin sending ...
New Sequence -----------
End sending ...
End sending ...
End sending ...
End sending ...
End sending ...
End sending ...
End sending ...
End sending ...
End sending ... Do something ...

End sending ...
End New Sequence -----------
End sending ...


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