diff --git a/dl/io/dl_net.cpp b/dl/io/dl_net.cpp index 9d2103a4..69dbc53f 100644 --- a/dl/io/dl_net.cpp +++ b/dl/io/dl_net.cpp @@ -157,7 +157,6 @@ public: } ~ServerUdpImp() { - _ioContext.stop(); } void _init(const asio::ip::address& addr, asio::ip::port_type port) @@ -208,6 +207,11 @@ public: #endif _read(); } + + void _stop() + { + _ioContext.stop(); + } }; //---------------------------------------Implement-------------------------------------- @@ -487,8 +491,10 @@ ServerUdp::ServerUdp() ServerUdp::~ServerUdp() { - delete _imp; + _imp->_stop(); + // 先删除线程,等待执行完后,再删自己 delete _t; + delete _imp; } void ServerUdp::_thread_run(void* p) diff --git a/dl/system/dl_thread.cpp b/dl/system/dl_thread.cpp index 93ea9bef..dcb8404c 100644 --- a/dl/system/dl_thread.cpp +++ b/dl/system/dl_thread.cpp @@ -26,7 +26,8 @@ namespace dl _t.join(); while (true) { - if (_state != 0) + // 必须完成线程后,才能删除自己 + if (_state == 1) break; std::this_thread::sleep_for(std::chrono::seconds(0)); }