Boost logo

Boost :

From: Philip Nash (philip.nash_at_[hidden])
Date: 2001-08-13 08:38:26

> -----Original Message-----
> From: Michael Kenniston [mailto:Msk_at_[hidden]]
> Sent: 13 August 2001 14:59
> To: boost_at_[hidden]
> Subject: [boost] statics and singletons [was boost.threads [was
> sockets/network ...] ]
> John Max Skaller and Bill Kempf wrote:
> > > I believe every single use of static variables
> > > and singletons is BAD DESIGN.
> > Well, I don't agree. <snip> there are several
> > classes of designs that simply can't be coded with out the use of
> > global data.
> > > Show me one. I've never seen one. I've never used
> > > global data (not since the '70's anyhow).
> > > [lexical scanner example snipped]
> While I don't have enough experience with singletons to
> convincingly argue either side, I do have enough experience
> to find this discussion very interesting, especially when it
> includes specific examples like the lexical scanner.
> Personally I'd like to see the debate continue, with additional
> cases proposed as requiring singletons or static variables, and
> rebuttals showing how/why they can/should be avoided (although
> perhaps we should let Mr. Kempf finish the threads library
> first :-).

I have recently had to use globals in order to be called from a C interface,
which expects state to be global. Nonetheless I wrapped all the "global"
data up into a class and held an object of its type in a single global smart

> We might not "resolve" the issue to everyone's
> satisfaction, but it could still be very enlightening and help
> many of us raise the level of our design skills. Even if nobody
> is brave enough to attempt an implementation of a boost singleton
> library right now (and I know I'm not), this discussion could lay
> the foundation for some documentation for it that supplies examples
> of when singletons should and should not be used and why.

Personally I think the Singleton implementation provided by Andrei
Alexandrescu in his "Modern C++ Design" book is pretty good. I'm not saying
it can't be improved on (he starts out by conceding that the Singleton
concept can have many incarnations, but his implementation provides most of
the usual variations through policies).
There may be other problems with it - maybe someone else could give some
examples - but as I see it a likely obstacle to having a Loki-like Singleton
accepted into boost is that it relies heavily on atexit(), which seems to be
inconsistently implemented across compilers.
Does anyone have any workarounds for that?


Boost list run by bdawes at, gregod at, cpdaniel at, john at