Note that there are some explanatory texts on larger screens.

plurals
  1. POboost::asio -- asio_handler_deallocate is called in io_service::~io_service(), after io_service::stop()
    primarykey
    data
    text
    <p>I have an <code>ip::udp::socket</code> constructed with an <code>io_service</code>. There is only one <code>boost::thread</code> which calls the <code>io_service::run()</code> method, and an instance of <code>io_service::work</code> to prevent <code>io_service::run()</code> from returning. The completion handlers for my <code>ip::udp::socket</code> have custom <code>asio_handler_allocate()</code> and <code>asio_handler_deallocate()</code> functions, which are backed by a <code>my::custom_memory_pool</code>.</p> <p>When my application quits, this sequence of events occurs on on my shutting-down thread:</p> <ol> <li><code>ip::udp::socket::close()</code></li> <li><code>work::~work()</code></li> <li><code>io_service::stop()</code></li> <li><code>thread::join()</code></li> <li><code>my::custom_memory_pool::~custom_memory_pool()</code></li> <li><code>ip::udp::socket::~socket()</code></li> <li><code>thread::~thread()</code></li> <li><code>io_service::~io_service()</code></li> </ol> <p>In step 8, the call to <code>io_service::~io_service()</code> causes...</p> <pre><code>Program terminated with signal 11, Segmentation fault. #0 0x00000000005ad93c in my::custom_memory_pool&lt;boost::aligned_storage&lt;512u, -1u&gt; &gt;::deallocate (this=0x36323f8, t=0x7fca97a07880) at memory.hpp:82 82 reinterpret_cast&lt;pool_node*&gt;(t)-&gt;next_ = head_; (gdb) bt 30 #0 0x00000000005ad93c in my::custom_memory_pool&lt;boost::aligned_storage&lt;512u, -1u&gt; &gt;::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&lt;socket_multicast::completion_handler&gt; (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&lt;boost::asio::mutable_buffers_1, boost::asio::ip::basic_endpoint&lt;boost::asio::ip::udp&gt;, socket_multicast::completion_handler&gt;::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&lt;boost::asio::mutable_buffers_1, boost::asio::ip::basic_endpoint&lt;boost::asio::ip::udp&gt;, socket_multicast::completion_handler&gt;::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=&lt;value optimized out&gt;) at /usr/include/boost/asio/detail/impl/service_registry.ipp:43 #8 0x0000000000428e99 in boost::asio::io_service::~io_service (this=0xd49f38, __in_chrg=&lt;value optimized out&gt;) at /usr/include/boost/asio/impl/io_service.ipp:51 </code></pre> <p>So the <code>io_service::~io_service()</code> is trying to deallocate some memory to the pool that I destroyed back in step 5.</p> <p>I can't move <code>my::custom_memory_pool::~custom_memory_pool()</code> to after <code>io_service::~io_service()</code>.</p> <p>I expected that after <code>io_service::stop()</code> and <code>thread::join()</code> returns, there could be no more <code>asio_handler_deallocate()</code> calls. Apparently that's not the case. What can I do in step 3 to force <code>io_service</code> to dequeue all of its completion events and deallocate all of its handler memory, and how can I block until <code>io_service</code> finishes those tasks?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload