fix CurlThreadPool destroy logic

This commit is contained in:
2025-05-14 19:29:07 +03:00
parent ce1aee1553
commit 8f3456a650
2 changed files with 10 additions and 1 deletions

View File

@@ -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) {

View File

@@ -24,6 +24,7 @@ private:
void procClient(PIHTTPClient * c);
PIProtectedVariable<PIQueue<PIHTTPClient *>> clients;
PIProtectedVariable<PIVector<PIHTTPClient *>> clients_in_proc;
PISemaphore sem;
PIVector<PIThread *> threads;
std::atomic_bool exiting = {false};