[Intrusive] safe_link assertion with list
I am using Fedora 9, gcc 4.3.0, and boost 1.38.0. I get the following error when calling the destroyMessage function. boost/intrusive/detail/utilities.hpp:421: void boost::intrusive::detail::destructor_impl(Hook&, boost::intrusive::detail::link_dispatch<safe_link>) [with Hook = boost::intrusive::detail::generic_hook<boost::intrusive::get_list_node_algo<void*>, boost::intrusive::default_tag, safe_link, 1>]: Assertion `!hook.is_linked()' failed. class MessageHook : public boost::intrusive::list_base_hook<>{ public: MessageHook(Message* msg) : m_msg(msg) {}; Message* GetMsg() { return m_msg; } private: Message* m_msg; }; class MessageFactory { public: MessageFactory() { } ~MessageFactory() { } ... virtual void destroyMessage( Message* msg ) { MessageHook hook(msg); m_message_list.push_back( hook ); } private: boost::intrusive::list<stockTraderMessageHook> m_message_list; }; Thanks
Pearl Rothman wrote:
I am using Fedora 9, gcc 4.3.0, and boost 1.38.0.
I get the following error when calling the destroyMessage function.
virtual void destroyMessage( Message* msg ) { MessageHook hook(msg); m_message_list.push_back( hook ); }
private: boost::intrusive::list<stockTraderMessageHook> m_message_list; };
Take in care that intrusive containers don't store copies of objects but objects themselves. So in destroyMessage "hook" is going to be destroyed while inserted in m_message_list and that's why you get the assertion. See documentation: http://www.boost.org/doc/libs/1_39_0/doc/html/intrusive/intrusive_vs_nontrus... Maybe you just need std::list instead of intrusive. Best, Ion
I am not trying to store a copy. I am trying to store the original Message itself, and not have the container delete the Message when I remove it.. Essentially I want to have m_message_list store Messages that I can remove, use, and then re-add to it.. How can I fix the code? Once I add Message to the list, I do not need it anywhere else. How can I fix the code? How can I fix my code to do this? 2009/6/10 Ion Gaztañaga <igaztanaga@gmail.com>
Pearl Rothman wrote:
I am using Fedora 9, gcc 4.3.0, and boost 1.38.0.
I get the following error when calling the destroyMessage function.
virtual void destroyMessage( Message* msg )
{ MessageHook hook(msg); m_message_list.push_back( hook ); }
private: boost::intrusive::list<stockTraderMessageHook> m_message_list; };
Take in care that intrusive containers don't store copies of objects but objects themselves. So in destroyMessage "hook" is going to be destroyed while inserted in m_message_list and that's why you get the assertion. See documentation:
http://www.boost.org/doc/libs/1_39_0/doc/html/intrusive/intrusive_vs_nontrus...
Maybe you just need std::list instead of intrusive.
Best,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG Pearl Rothman wrote:
I am using Fedora 9, gcc 4.3.0, and boost 1.38.0.
I get the following error when calling the destroyMessage function.
boost/intrusive/detail/utilities.hpp:421: void boost::intrusive::detail::destructor_impl(Hook&, boost::intrusive::detail::link_dispatch<safe_link>) [with Hook = boost::intrusive::detail::generic_hook<boost::intrusive::get_list_node_algo<void*>, boost::intrusive::default_tag, safe_link, 1>]: Assertion `!hook.is_linked()' failed.
<snip> virtual void destroyMessage( Message* msg ) { MessageHook hook(msg); m_message_list.push_back( hook ); }
Boost.Intrusive expects you to manage the memory for the nodes. When the function returns, m_message_list will be left with a dangling pointer to hook, hence the assertion. In Christ, Steven Watanabe
participants (3)
-
Ion Gaztañaga
-
Pearl Rothman
-
Steven Watanabe