diff --git a/apps/master/AdminRest.cpp b/apps/master/AdminRest.cpp index 74b93e46d..5afab2b00 100644 --- a/apps/master/AdminRest.cpp +++ b/apps/master/AdminRest.cpp @@ -58,10 +58,12 @@ void AdminRest::start() *response << response400; }; - httpServer.start(); + thr = thread([this](){httpServer.start();}); } void AdminRest::stop() { httpServer.stop(); + if(thr.joinable()) + thr.join(); } diff --git a/apps/master/AdminRest.hpp b/apps/master/AdminRest.hpp index 26a853f45..6705051a2 100644 --- a/apps/master/AdminRest.hpp +++ b/apps/master/AdminRest.hpp @@ -19,6 +19,7 @@ public: private: HttpsServer httpServer; std::shared_ptr master; + std::thread thr; }; diff --git a/apps/master/RestServer.cpp b/apps/master/RestServer.cpp index 58cb31ed9..726a3a47a 100644 --- a/apps/master/RestServer.cpp +++ b/apps/master/RestServer.cpp @@ -167,7 +167,7 @@ void RestServer::start() *response << response400; }; - httpServer.start(); + thr = thread([this](){httpServer.start();}); } void RestServer::cacheUpdated() @@ -178,4 +178,6 @@ void RestServer::cacheUpdated() void RestServer::stop() { httpServer.stop(); + if(thr.joinable()) + thr.join(); } diff --git a/apps/master/RestServer.hpp b/apps/master/RestServer.hpp index 1107660cf..3b52ebb6a 100644 --- a/apps/master/RestServer.hpp +++ b/apps/master/RestServer.hpp @@ -24,6 +24,7 @@ private: HttpServer httpServer; MasterServer::ServerMap *serverMap; bool updatedCache = true; + std::thread thr; }; diff --git a/apps/master/main.cpp b/apps/master/main.cpp index 0639f3872..938e379a2 100644 --- a/apps/master/main.cpp +++ b/apps/master/main.cpp @@ -67,12 +67,8 @@ int main(int argc, char* argv[]) signal(SIGTERM, onExit); masterServer->Start(); - - thread rest_thread([]() { restServer->start();}); - thread restAdmin_thread([]() { restAdminServer->start();}); - - rest_thread.join(); - restAdmin_thread.join(); + restServer->start(); + restAdminServer->start(); masterServer->Wait(); return 0;