|
Boost : |
Subject: Re: [boost] Request for Feedback on the Singularity Design Pattern
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-06-28 23:47:23
On Tue, Jun 28, 2011 at 8:13 PM, Gottlob Frege <gottlobfrege_at_[hidden]>wrote:
> On Mon, Jun 27, 2011 at 2:17 AM, Ben Robinson <icaretaker_at_[hidden]>
> wrote:
> > The Singularity Design Pattern...
> >
> > The source files are available here:
> >
> > http://www.mediafire.com/?d8kn5fx2n5d22
> >
> > I look forward to your feedback.
> >
> > Thank you,
> >
> > Ben Robinson, Ph.D.
>
> When does the constructor
> template <class T> ::boost::scoped_ptr<T> singularity_instance<T>::ptr(0);
> 'happen'?
>
> ie there can be problems with the construction order of globals.
>
The private pointer is statically initialized, but is initialized to zero.
Only when the user calls singularity<T>::create(), is the pointer reset to
hold the newly created object. Therefore, there should be no issues with
the construction order of globals...
Unless, you decide to put that ::create() call in the constructor of
another, non-singularity global. I would argue however, that the problem
there is not with the singularity itself, but the fact that it was contained
and initialized inside a global. Singularity can't forbid you from doing
that, and if you do so, you give up control of the lifetime of the
singularized object. The recommended usage is to call create() eagerly
after main, and store the reference, and pass it to whomever needs it.
I appreciate your inquiry,
Ben Robinson, Ph.D.
> Tony
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk