I'm working with the qpid messaging library. I have a singleton class that holds connection objects. I noticed that my application would core on exit depending on how I created the connection. If I created it in the singleton constructor or a static method everything was fine, however if I created it in a non-static method, or in my getinstance method as shown below the messaging library would internally call a close method before my destructor was called and it would call an abort. I was wondering what about these creation calls is different that could cause such a result.
class Singleton : public boost::noncopyable
{
public:
static Singleton &
GetInstance()
{
static Singleton tS;
// If I create _Conn this way it cores
// tS._Conn = SharedConn(new Conn());
return tS;
}
private:
typedef boost::shared_ptr< Conn > SharedConn;
Singleton()
{
// If I create _Conn this way it works
//_Conn = SharedConn(new Conn());
}
SharedConn _Conn;
};
int main(int argc, char** argv)
{
Singleton::GetInstance();
return 0;
}