From: Otto Moerbeek Date: Fri, 8 Nov 2019 13:34:39 +0000 (+0100) Subject: Make threads run until asked to stop. X-Git-Tag: dnsdist-1.4.0~12^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31a8c1b3f8663df9a265e79f0bdf132f245b3417;p=thirdparty%2Fpdns.git Make threads run until asked to stop. This is safer since the atexit handler is not ran while threads are still active. Also, when using valgrind we get more clean leak reports. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 5e1d794324..bb2f617639 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4313,7 +4313,9 @@ static int serviceMain(int argc, char*argv[]) infos.isHandler = true; infos.thread = std::thread(recursorThread, 0, "web+stat"); - s_threadInfos.at(0).thread.join(); + for (auto & ti : s_threadInfos) { + ti.thread.join(); + } } return 0; } @@ -4448,7 +4450,8 @@ try time_t carbonInterval=::arg().asNum("carbon-interval"); time_t luaMaintenanceInterval=::arg().asNum("lua-maintenance-interval"); counter.store(0); // used to periodically execute certain tasks - for(;;) { + + while (!RecursorControlChannel::stop) { while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing if(!(counter%500)) { @@ -4516,6 +4519,7 @@ try } } } + return 0; } catch(PDNSException &ae) { g_log<