You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The name is not accurate
The classes name SingletonPtr is confusing. This is not a singleton. We can create multiple instances of the same class. Therefore similar pattern in another code base is called LazyInstance for example.
Thread safety
This is not thread-safe, is it?:
if (NULL == _ptr) {
singleton_lock();
_ptr = new (_data) T;
singleton_unlock();
}
Initialization of T type
It's not clear what SingletonPtr guarantees regarding initialization of a T object.
if (NULL == _ptr) {
singleton_lock();
_ptr = new (_data) T;
singleton_unlock();
}
If T is POD, its data are not initialized (at least C++03,C++98). should it be _ptr = new (_data) T(); ?
The destructor for the T object
There could be a method to destroy T object (call explicitly dtor).