Boost logo

Boost :

Subject: Re: [boost] Thread-safe singleton pattern
From: Alex Miller (alex55miller_at_[hidden])
Date: 2010-01-25 22:25:25


Your implementation seems to be a fairly standard implementation of double
checked locking, and thus is likely vulnerable to the issues outlined in C++
and the Perils of Double-Checked
Locking<http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf>
.

On Mon, Jan 25, 2010 at 7:44 PM, GMan <gmannickg_at_[hidden]> wrote:

> This suffers from the same problems as your last singleton. (Probably
> should
> have kept it in that discussion, by the way.). Also, instead of forcing
> people to have threaded or not, make it a policy.
>
> On Mon, Jan 25, 2010 at 3:49 PM, Andrew Chinkoff <achinkoff_at_[hidden]
> >wrote:
>
> > I propose thread safe singleton pattern implementation
> > (see http://www.research.ibm.com/designpatterns/pubs/ph-jun96.txt).
> >
> > I have attached "singleton.hpp" to this letter.
> >
> > Below is the test program:
> >
> > #include <stdio.h>
> > #include <singleton.hpp>
> >
> > class A : public boost::Singleton<A>
> > {
> > //
> > // Only Singleton class can create and delete us!
> > //
> > SINGLETON_IS_MY_FRIEND;
> > public:
> > void foo(){ printf("foo!\n"); }
> > A(){ printf("A()\n"); }
> > ~A(){ printf("~A()\n"); }
> > };
> >
> > void main()
> > {
> > // It is not compiled:
> > //A a = A::Instance();
> > // That is exactly as it should be used:
> > A::Instance().foo();
> > }
> >
> > Test program outputs:
> > A()
> > foo!
> > ~A()
> >
> > My question: Does Boost community think that boost::Singleton is
> convenient
> > (or successful) solution?
> >
> > _______________________________________________
> > Unsubscribe & other changes:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
>
>
>
> --
> GMan, Nick Gorski
> _______________________________________________
> 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