Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-02-20 11:17:06


I compiled and ran your example on my vc 7.1 environment and was able to
reproduce the situation.

I modified your main function so that the test worked.

int main()
{
test_serialize();
atexit(&f);
return 0;
}

So I suppose you can get things to work by ensuring that there is a "dummy"
serialization before your register with atexit. Personally I wouldn't be
comfortable with this as it would depend on undefined behavior and wouldnt
guarentee portability. But it might be good enough for your purposes.

Your "dummy" serializaton could output to a null stream and just use
"register" to make sure all the statics for all the types instantiated.

The idea of calling serialization from a function registered with atexit
would seem to be a very bad idea to me. Better would be to slightly factor
your solution into:

class my_main {
    main(....)
    ~my_main(){
        test_serialize();
    }
};

main(...){
    my_main(...);
}

This would guarentee that all the serializations occur before the statics
are destroyed.

Robert Ramey

gast128 wrote:
> 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.


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