Hi Martin,
After a first glance it seems strange that you are only requesting the
lock (sync_init) in get_instance(), which seems to be ok anyway (after quite
a lot of shared_ptr/weak_ptr internals). Now I wonder whether the busy wait
is needed or the combination of a mutex and a condition variable could be
better, waking the waiting thread just when destruction of the object
completes.
Also I am not sure of the necessity of having both a start_construction()
and finish_construction() that require two mutex acquisitions:
// Using boost::condition:
struct dynamic_singleton::impl : private boost::noncopyable
{
impl() {}
~impl() {}
static void start_construction()
{
boost::recursive_mutex::scoped_lock lock( sync_ );
while ( the_object_exists ) {
cond_.wait( lock );
}
the_object_exists = true;
}
static void finish_destruction()
{
boost::recursive_mutex::scoped_lock lock( sync_ );
the_object_exists = false;
cond_.notify_one();
}
typedef boost::weak_ptr