serialization singleton assert on iphone
Hi,
I have an assert when exiting my application using the serialization lib of
boost 1.38.
BOOST_DLLEXPORT static T & get_instance() {
static detail::singleton_wrapper<T> t;
// refer to instance, causing it to be instantiated (and
// initialized at startup on working compilers)
assert(! detail::singleton_wrapper<T>::m_is_destroyed);
use(instance);
return static_cast
It would be interesting to know the stack trace for this to know from where
the call is being made. This suggests that the order of destruction is
different than what the library expects. So other informaition
such as compiler version etc are also interesting.
Robert Ramey
"gtsml owevwr"
AFAIK, the order of destruction is the reverse of the order of
construction, though the latter is unspecified between compilation
units.
I've found singletons when implemented as global objects to be very
difficult to deal with. My solution has been to leave it up to the
user to make the singleton global (and deal with the consequences) if
they want to. So the library provides:
class singleton;
boost::shared_ptr<singleton> library_init();
void library_do_something( singleton &, ......... );
If someone wants to, they can store the singleton in their own global
object library_singleton:
boost::shared_ptr<singleton> library_singleton=library_init();
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
On Mon, Apr 13, 2009 at 9:53 AM, Robert Ramey
It would be interesting to know the stack trace for this to know from where the call is being made. This suggests that the order of destruction is different than what the library expects. So other informaition such as compiler version etc are also interesting.
Robert Ramey
"gtsml owevwr"
wrote in message news:6e954aa60904130810x143a0516j8380e40384eb0c07@mail.gmail.com... Hi, I have an assert when exiting my application using the serialization lib of boost 1.38.
BOOST_DLLEXPORT static T & get_instance() { static detail::singleton_wrapper<T> t; // refer to instance, causing it to be instantiated (and // initialized at startup on working compilers) assert(! detail::singleton_wrapper<T>::m_is_destroyed); use(instance); return static_cast
(t); } The same code doesn't assert on windows XP so I guess that's something messy with static allocation on the iphone platform. On the iphone, the load/save code works well as long as it's not called when the application exit.
As far I as I understand, I need to move my exit code somewhere else, when those singleton are still allocated. Can somebody confirm that? Or maybe I'm missing something...
Any feedback warmly welcome!
thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks for your comments. For those who might encounter the same error: The solution consist in calling the serializer in "applicationWillTerminate" instead of "deallocate".Those two functions are cocoa delegate (ie callback).
participants (3)
-
Emil Dotchevski
-
gtsml owevwr
-
Robert Ramey