From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-02-26 15:55:52
>I have encountered a bug when using BOOST_SP_USE_QUICK_ALLOCATOR with
> shared_ptr<> objects that are contained in a static container. This bug
> verifiable with Visual Studio 2005 SP1 as well as MinGW GCC 4.2.1.
> As an example, I have created a static std::map, which pairs a long with a
> boost::shared_ptr<>. This is the scenario where I first encountered the
> bug. The boost preprocessor definition BOOST_SP_USE_QUICK_ALLOCATOR is
> defined. When the program exists, the application crashes during
> deallocation of the shared_ptrs.
This is indeed a problem caused by destruction order. The static map is
initialized before the mutex, and is therefore destroyed after it. You
should be able to work around the issue by adding a dummy
static boost::shared_ptr<tTestItem> p( (tTestItem*)0 );
before the map, ensuring that the quick_allocator will be invoked before the
map construction, initializing the mutex.
Another (more time-consuming) option is to roll your own "quick allocator"
that doesn't suffer from initialization order problems and use the allocator
constructor of shared_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk