Rosetta Utilities  2014.35
utility::thread Namespace Reference


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...

Function Documentation

template<class T >
void utility::thread::safely_create_singleton ( T *&  instance)
template<class T >
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(),