![]() |
Rosetta
3.7
|
Functions | |
template<class T > | |
void | safely_create_singleton (T *&instance) |
template<class T > | |
void | safely_create_singleton (boost::function< T *() > creation_func, T *&instance) |
Safely instantiate a singleton class in a (possibly) multithreaded context. More... | |
|
inline |
void utility::thread::safely_create_singleton | ( | boost::function< T *() > | creation_func, |
T *& | instance | ||
) |
Safely instantiate a singleton class in a (possibly) multithreaded context.
In the non-multithreaded case, this simply checks the singleton's instance member; in the multithreaded case, it checks the instance member, then it obtains the singleton's instance-creation mutex, then it checks the instance member again, to ensure that no other thread has already created the instance, it creates the instance, and then it releases the mutex.
Requires that class T defines: static std::mutex & singleton_mutex(),
References test.T007_TracerIO::T.