Boost logo

Boost Users :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2005-08-29 15:00:03


On Aug 29, 2005, at 3:47 PM, Peter Dimov wrote:

> I haven't studied the threadmon code in detail, though. It might be
> possible
> to destroy the threadmon mutex safely at some point during shutdown.

I haven't studied threadmon either. But from the sounds of it, you may
want to consider a "phoenix" singleton, nicely documented in Andrei
Alexandrescu's MC++D. One hitch to get a working phoenix singleton is
to have a working atexit function (and I mean really working
correctly). There was a lwg dr report on it:

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#3

which has now received TC status, meaning it is a normative part of the
C++03 standard. I have no information on how well the various
platforms conform to the standard in this regard (it can be tested for
though).

The idea is fairly simple. The singleton factory keeps state that
tells it whether the singleton is constructed or not. When the
singleton gets constructed, it registers a "destructor" with atexit.
If after the atexit runs the destructor, the singleton is needed again,
then it recreates itself, and re-registers with atexit. A correctly
working atexit will properly run this newly registered function as it
continues to process the atexit chain.

-Howard


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net