File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
debug_router/native/socket Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ void WorkThreadExecutor::submit(std::function<void()> task) {
3434}
3535
3636void WorkThreadExecutor::shutdown () {
37+ std::shared_ptr<std::thread> worker_ptr;
3738 {
3839 std::lock_guard<std::mutex> lock (task_mtx);
3940 if (is_shut_down) {
@@ -42,18 +43,19 @@ void WorkThreadExecutor::shutdown() {
4243 is_shut_down = true ;
4344 std::queue<std::function<void ()>> empty;
4445 tasks.swap (empty);
46+ worker_ptr = std::move (worker); // take ownership of worker
4547 }
4648 cond.notify_all ();
4749
48- if (worker && worker ->joinable ()) {
50+ if (worker_ptr && worker_ptr ->joinable ()) {
4951#if __cpp_exceptions >= 199711L
5052 try {
5153#endif
52- if (worker ->get_id () != std::this_thread::get_id ()) {
53- worker ->join ();
54+ if (worker_ptr ->get_id () != std::this_thread::get_id ()) {
55+ worker_ptr ->join ();
5456 LOGI (" WorkThreadExecutor::shutdown worker->join() success." );
5557 } else {
56- worker ->detach ();
58+ worker_ptr ->detach ();
5759 LOGI (" WorkThreadExecutor::shutdown worker->detach() success." );
5860 }
5961#if __cpp_exceptions >= 199711L
@@ -63,7 +65,6 @@ void WorkThreadExecutor::shutdown() {
6365 }
6466#endif
6567 }
66- worker.reset ();
6768 LOGI (" WorkThreadExecutor::shutdown success." );
6869}
6970
You can’t perform that action at this time.
0 commit comments