当前位置:  开发笔记 > 编程语言 > 正文

在io_service :: stop()之后,在io_service :: ~io_service()中调用boost :: asio - asio_handler_deallocate

如何解决《在io_service::stop()之后,在io_service::~io_service()中调用boost::asio-asio_handler_deallocate》经验,为你挑选了0个好方法。

我有一个ip::udp::socket带有一个io_service.只有一个boost::thread调用io_service::run()方法,以及一个io_service::work防止io_service::run()返回的实例.我的完成处理程序ip::udp::socket有自定义asio_handler_allocate()asio_handler_deallocate()功能,由一个支持my::custom_memory_pool.

当我的应用程序退出时,这个事件序列发生在我的关闭线程上:

    ip::udp::socket::close()

    work::~work()

    io_service::stop()

    thread::join()

    my::custom_memory_pool::~custom_memory_pool()

    ip::udp::socket::~socket()

    thread::~thread()

    io_service::~io_service()

在步骤8中,调用io_service::~io_service()原因...

Program terminated with signal 11, Segmentation fault.
#0  0x00000000005ad93c in my::custom_memory_pool >::deallocate (this=0x36323f8, t=0x7fca97a07880)
    at memory.hpp:82
82                      reinterpret_cast(t)->next_ = head_;
(gdb) bt 30
#0  0x00000000005ad93c in my::custom_memory_pool >::deallocate (this=0x36323f8, t=0x7fca97a07880)
    at memory.hpp:82
#1  0x00000000005ad40a in asio_handler_deallocate (p=0x7fca97a07880, s=96, h=0x7fffe09d5480) at net.cpp:22
#2  0x0000000000571a07 in boost_asio_handler_alloc_helpers::deallocate (p=0x7fca97a07880, s=96, h=...)
    at /usr/include/boost/asio/detail/handler_alloc_helpers.hpp:51
#3  0x0000000000558256 in boost::asio::detail::reactive_socket_recvfrom_op, socket_multicast::completion_handler>::ptr::reset (this=0x7fffe09d54b0)
    at /usr/include/boost/asio/detail/reactive_socket_recvfrom_op.hpp:81
#4  0x0000000000558310 in boost::asio::detail::reactive_socket_recvfrom_op, socket_multicast::completion_handler>::do_complete (owner=0x0, base=0x7fca97a07880)
    at /usr/include/boost/asio/detail/reactive_socket_recvfrom_op.hpp:112
#5  0x0000000000426706 in boost::asio::detail::task_io_service_operation::destroy (this=0x7fca97a07880)
    at /usr/include/boost/asio/detail/task_io_service_operation.hpp:41
#6  0x000000000042841b in boost::asio::detail::task_io_service::shutdown_service (this=0xd4df30)
    at /usr/include/boost/asio/detail/impl/task_io_service.ipp:96
#7  0x0000000000426388 in boost::asio::detail::service_registry::~service_registry (this=0xd4a320, __in_chrg=)
    at /usr/include/boost/asio/detail/impl/service_registry.ipp:43
#8  0x0000000000428e99 in boost::asio::io_service::~io_service (this=0xd49f38, __in_chrg=)
    at /usr/include/boost/asio/impl/io_service.ipp:51

所以io_service::~io_service()它试图将一些内存释放到我在第5步中销毁的池中.

我无法移动my::custom_memory_pool::~custom_memory_pool()到之后io_service::~io_service().

我预计,以后io_service::stop()thread::join()回报,有可能是没有更多的asio_handler_deallocate()电话.显然情况并非如此.我可以在步骤3中强制io_service将所有完成事件出列并取消分配其所有处理程序内存,以及如何阻止直到io_service完成这些任务?

推荐阅读
凹凸曼00威威_694
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有