From: Jason Hise (chaos_at_[hidden])
Date: 2005-03-01 17:48:53
I just got a message from Michel Decima regarding an interesting
problem. What happens when you have to use a library which maintains
static or global variables that you don't have control over, and you
need your singletons to have access to them? The answer is that you
have to make sure that your singletons get destroyed before or as main
ends, not after. To do so, you have one of three options:
A) Use the dependency_lifetime and make sure not to keep any static or
B) Explicitly call destroy on each of your singletons before main exits.
C) Explicitly destroy the secret singleton
boost::singleton::detail::longevity_registry before main exits.
I recommend option three, combined with some RAII. For example:
struct CleanupSingletons ( )
~ CleanupSingletons ( )
).destroy ( );
int main ( )
I wonder if this functionality is useful enough that I should add a
non-member function 'cleanup' directly in the singleton namespace which
destroys the longevity_registry internally. Thoughts and opinions?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk