Boost logo

Boost Users :

From: gast128 (gast128_at_[hidden])
Date: 2007-02-20 05:37:42


Dear all,

We use (too many) singletons in our program and now the program crashes in
Boost Serialization because in an onexit function a static member
(oserializer::instantiate) of Boost Serialization is already destroyed.

Is there a way to force an intialisation of these static members so that they
are destroyed after my singleton destroys?

The code can be reproduced by the follwing snippet:

//
#define BOOST_ALL_DYN_LINK
#define BOOST_LIB_DIAGNOSTIC

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/version.hpp>

struct Foo
{
   Foo() : m_i(0)
   {}
    
   template <class Archive>
   void serialize(Archive& ar, const unsigned int /*version*/)
   {
      ar & BOOST_SERIALIZATION_NVP(m_i);
   }

   int m_i;
};

void f ();
void test_serialize ();

//----------------------------------------------------------------------------
// Function main
//----------------------------------------------------------------------------
// Description : main
//----------------------------------------------------------------------------
int main()
{
   atexit(&f);
   
   test_serialize();
   
   return 0;
}

void f()
{
   test_serialize();
}

void test_serialize()
{
   std::ofstream ofs("test.xml");
   boost::archive::xml_oarchive oa(ofs);

   const Foo foo;
   oa << BOOST_SERIALIZATION_NVP(foo);
}

wkr,
me


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