From 93129d0761fa0cab3bc5db38586fd5c8b4d2efbe Mon Sep 17 00:00:00 2001 From: Lveyou <1339484752@qq.com> Date: Tue, 3 Mar 2026 14:23:40 +0800 Subject: [PATCH] =?UTF-8?q?*=20udp=E9=87=8A=E6=94=BE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/io/dl_net.cpp | 10 ++++++++-- dl/system/dl_thread.cpp | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) 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)); }