gpt4 book ai didi

c++ - Boost UDP套接字上的SIGSEGV关闭-malloc.c上的tcache_get

转载 作者:行者123 更新时间:2023-12-02 10:39:14 25 4
gpt4 key购买 nike

我不知道这个问题可能来自哪里:
(使用GDB进行调试):

terminate called after throwing an instance of '[Thread 0x7ffff5e68700 (LWP 24945) exited]
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'

线程1“random_walkerta”收到信号SIGSEGV,段错误。
talloc_get(tc_idx = 1)在malloc.c:2943

StackTrace:
#0  tcache_get (tc_idx=1) at malloc.c:2943
#1 __GI___libc_malloc (bytes=31) at malloc.c:3050
#2 0x00007ffff6ec154c in operator new(unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff6f56dbf in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff6f584bb in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00005555555bee66 in boost::system::system_error::what (
this=0x5555558a1bf0) at /usr/include/boost/system/system_error.hpp:70
#6 0x00007ffff6eba8ba in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff6ec0d3a in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8 0x00007ffff6ebfd59 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9 0x00007ffff6ec0708 in __gxx_personality_v0 ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ffff6888763 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#11 0x00007ffff688907d in _Unwind_Resume ()
from /lib/x86_64-linux-gnu/libgcc_s.so.1
#12 0x00005555555cb8d6 in boost::asio::detail::do_throw_error (err=...,
location=0x555555610dba "close")
at /usr/include/boost/asio/detail/impl/throw_error.ipp:37
---Type <return> to continue, or q <return> to quit---
#13 0x00005555555cb741 in boost::asio::detail::throw_error (err=...,
location=0x555555610dba "close")
at /usr/include/boost/asio/detail/throw_error.hpp:42
#14 0x00005555555de022 in boost::asio::basic_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >::close (
this=0x555555887ea0) at /usr/include/boost/asio/basic_socket.hpp:356
#15 0x00005555555d7ebe in Vast::net_overhearing_handler::handle_close (
this=0x555555889490) at net_overhearing_handler.cpp:160
#16 0x00005555555d7e4c in Vast::net_overhearing_handler::close (
this=0x555555889490) at net_overhearing_handler.cpp:141
#17 0x00005555555c9b85 in Vast::net_overhearing::stop (this=0x5555558870e0)
at net_overhearing.cpp:88
#18 0x00005555555ba77f in Vast::VASTnet::~VASTnet (this=0x55555587f180,
__in_chrg=<optimized out>) at VASTnet.cpp:63
#19 0x000055555556ca7a in Vast::destroyNet (net=0x55555587f180)
at VASTVerse.cpp:93
#20 0x000055555556d036 in Vast::VASTVerse::~VASTVerse (this=0x55555587e4c0,
__in_chrg=<optimized out>) at VASTVerse.cpp:196
#21 0x000055555556bce4 in main (argc=1, argv=0x7fffffffe598)
at random_walkertalker.cpp:266

设置如下:
我有一个在单独的线程io_service上运行的Boost UDP套接字,用于监听数据包。一切都按预期进行,直到我尝试关闭程序,UDP套接字和io_service。我猜我没有正确关闭某些设备。

以下是用于关闭UDP和io_services的代码:
if (_io_service != NULL) {
_io_service->reset();
_udp->close(); //This line is giving the error (160)


_io_service->stop();
_iosthread->join();
}

启动时,我将执行以下操作:
_udp = new ip::udp::socket(*_io_service);
_udp->open(ip::udp::v4());

_udp->async_receive_from(
boost::asio::buffer(_buf, VAST_BUFSIZ), _remote_endpoint_,
boost::bind(&net_overhearing_handler::handle_input, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));

_iosthread = new boost::thread(boost::bind(&boost::asio::io_service::run, io_service));

最佳答案

删除此行

 _io_service->reset();

因为根据引用 io_service::reset

This function must not be called while there are any unfinished calls to the run(), run_one(), poll() or poll_one() functions.



当您调用 run时, restart方法似乎可以在线程中工作。

您无需调用此方法即可停止 io_service::run方法。通过调用 run可以取消 _io_service->stop();中所有待处理的操作,然后 run停止,您的线程也终止。

关于c++ - Boost UDP套接字上的SIGSEGV关闭-malloc.c上的tcache_get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52738515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com