threading really works against this design, especially if you want a pure singleton. you can visualize it like so:
class t_singleton { public: static t_singleton& Get() { /* thread safety is a consideration here: */ t_auto_ptr<t_singleton>& shared(Shared()); if (shared.isNull()) { shared.setObject(new t_singleton); } /* and you should manage external references using another container type: */ return Shared().reference(); } static void DestroyIt() { /* thread safety is a consideration here: */ Shared().destroy(); } private: static t_auto_ptr<t_singleton>& Shared() { static t_auto_ptr<t_singleton> s_Shared; return s_Shared; } private: t_singleton(); ~t_singleton(); };
but this should also suggest many threading red flags with pure singletons.
If you really want to extend this and enforce a pure singleton, you would need proper reference counting containers -- this suggests a singleton is a bad solution for this problem in multiple ways, and just adds a ton of unnecessary complexity. good luck!