boost udp::socket(io_service,endpoint)偶尔发生segment fault

在做多线程开发时,接收udp广播包,定义udp socket如下:

try
    {

        hdl_udp_socket_ = new boost::asio::ip::udp::socket(hdl_socket_service_,
                                                           boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4::any(), hdl_udp_endpoint_.port()));

        hdl_socket_service_.run();
    }
    catch (const std::exception &e)
    {

在触发这段程序运行时,会偶尔出现segment fault的问题,程序崩掉,并不是每次想要执行程序时都会发生。经过输出打印,确定是在

hdl_udp_socket_ = new boost::asio::ip::udp::socket(hdl_socket_service_,
                                                           boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4::any(), hdl_udp_endpoint_.port()));

        hdl_socket_service_.run();

该处发生,但可以肯定的是hdl_udp_endpoint_.port()一定存在,hdl_socket_service在.h文件中定义(boost::asio::io_service hdl_socket_service_;),但没有初始化(不知道怎么初始化)
此外在接收广播包的函数中也会出现free(): invaild pointer的错误:

length = hdl_udp_socket_->receive_from (boost::asio::buffer (data, 2000), sender_endpoint);

经过输出打印 可以确定该问题出在receive_from函数中,经查找boost中该函数,首先需要udp_socket.get_io_service()获得该udp socket的io_service,所以怀疑是否都是io_service的问题。
解决方法:找到为什么会io_service对象不能被找到,或者有方法检测io_service是否存在

https://blog.csdn.net/u011073673/article/details/53116764