template<typename _T> public ref class Singleton : public _T
{
public:
static _T^ Instance(void)
{
if (_instance == nullptr)
{
_mut->WaitOne();
try
{
if (_instance == nullptr)
{
_instance = safe_cast<_T^>(gcnew Singleton<_T>);
}
}
finally
{
_mut->ReleaseMutex();
}
}
return _instance;
}
protected:
Singleton(void){}
protected:
static _T^ _instance = nullptr;
static System::Threading::Mutex^ _mut = gcnew System::Threading::Mutex();
};