From 8f3456a6502521c106156e69f285bc755a6deaeb Mon Sep 17 00:00:00 2001 From: peri4 Date: Wed, 14 May 2025 19:29:07 +0300 Subject: [PATCH] fix CurlThreadPool destroy logic --- libs/http_client/curl_thread_pool_p.cpp | 10 +++++++++- libs/http_client/curl_thread_pool_p.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/http_client/curl_thread_pool_p.cpp b/libs/http_client/curl_thread_pool_p.cpp index 8e188f0c..d9b1bfc7 100644 --- a/libs/http_client/curl_thread_pool_p.cpp +++ b/libs/http_client/curl_thread_pool_p.cpp @@ -8,7 +8,8 @@ CurlThreadPool::CurlThreadPool() { curl_global_init(CURL_GLOBAL_DEFAULT); - piForTimes(10) { + const int count = 10; + for (int i = 0; i < count; ++i) { auto * t = new PIThread([this]() { threadFunc(); }, true); threads << t; } @@ -43,7 +44,9 @@ void CurlThreadPool::threadFunc() { void CurlThreadPool::procClient(PIHTTPClient * c) { + { clients_in_proc.getRef()->append(c); } if (c->init()) c->perform(); + { clients_in_proc.getRef()->removeOne(c); } delete c; } @@ -70,6 +73,11 @@ void CurlThreadPool::destroy() { for (auto c: *cr) c->abort(); } + { + auto cr = clients_in_proc.getRef(); + for (auto c: *cr) + c->abort(); + } // piCout << "~CurlThreadPool release ..."; sem.release(threads.size()); for (auto * t: threads) { diff --git a/libs/http_client/curl_thread_pool_p.h b/libs/http_client/curl_thread_pool_p.h index 9b6a6bfe..d715558f 100644 --- a/libs/http_client/curl_thread_pool_p.h +++ b/libs/http_client/curl_thread_pool_p.h @@ -24,6 +24,7 @@ private: void procClient(PIHTTPClient * c); PIProtectedVariable> clients; + PIProtectedVariable> clients_in_proc; PISemaphore sem; PIVector threads; std::atomic_bool exiting = {false};