diff --git a/include/cserver/engine/basic/task_processor.hpp b/include/cserver/engine/basic/task_processor.hpp index fa979c6..d41ca47 100644 --- a/include/cserver/engine/basic/task_processor.hpp +++ b/include/cserver/engine/basic/task_processor.hpp @@ -8,7 +8,7 @@ namespace cserver::engine::basic { template struct TaskProcessor { boost::asio::io_context ioContext; - std::array pool; + std::array pool; static constexpr utempl::ConstexprString kName = "basicTaskProcessor"; inline constexpr TaskProcessor(auto, auto&) : ioContext{}, @@ -23,10 +23,15 @@ struct TaskProcessor { return {}; }); }; + inline constexpr ~TaskProcessor() { + for(auto& thread : this->pool) { + thread.join(); + }; + }; inline auto Run() { for(auto& thread : this->pool) { - thread = std::jthread([&]{ + thread = std::thread([&]{ boost::asio::executor_work_guardioContext.get_executor())> guard{this->ioContext.get_executor()}; this->ioContext.run(); });