Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-07-20 13:18:27

From: Vesa Karvonen <vesa.karvonen_at_[hidden]>
> From: "Greg Colvin" <gcolvin_at_[hidden]>
> > Anyway, a simple template for this idiom might be a useful addition to
> > Boost.
> I believe a simple template might cause more problems than it would solve.
> instance, neither of the above are thread safe, and the destruction order
> still cause problems.

There doesn't exist a "simple template" solution. FYI, Boost.Pool has a
convoluted template solution for its particular singleton needs; it's under
<boost/pool/detail/singleton.hpp>, if anyone's interested.

It has the following properties:
. If the singleton instance is never referenced, then it's never created.
. The singleton is created before main() begins if it is referenced, and is
destroyed after main() ends; thus, it can be thread safe IF there is only
one thread running at those times. (It does *not* use the double-checked
locking idiom).
. The singleton may be safely referenced by any global object constructor;
initialization order has no effect.

and the following restrictions:
. No special behaviour is provided for singleton destruction; the intention
is that if the singleton is required in a global object's destructor, then
put a reference to it in the constructor.
. The code for Boost.Pool's singleton only supports singleton types with
default constructors.

This header has the intent that it will eventually be replaced by a
Boost.Singleton library. Which no-one has been brave enough to try :)


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