| 253 | |
| 254 | template <typename Thread> |
| 255 | void ThreadPoolImpl<Thread>::finalize() |
| 256 | { |
| 257 | { |
| 258 | std::unique_lock lock(mutex); |
| 259 | shutdown = true; |
| 260 | /// We don't want threads to remove themselves from `threads` anymore, otherwise `thread.join()` will go wrong below in this function. |
| 261 | threads_remove_themselves = false; |
| 262 | } |
| 263 | |
| 264 | new_job_or_shutdown.notify_all(); |
| 265 | |
| 266 | std::vector<size_t> tids; |
| 267 | std::stringstream ss; |
| 268 | ss << "["; |
| 269 | tids.reserve(threads.size()); |
| 270 | |
| 271 | for (auto & thread : threads) |
| 272 | { |
| 273 | thread.join(); |
| 274 | if constexpr (std::is_same_v<ThreadFromGlobalPool, Thread>) |
| 275 | { |
| 276 | tids.emplace_back(thread.gettid()); |
| 277 | ss << thread.gettid() << ", "; |
| 278 | } |
| 279 | } |
| 280 | ss << "]"; |
| 281 | |
| 282 | |
| 283 | if (!tids.empty()) |
| 284 | { |
| 285 | auto & cgroup_manager = DB::CGroupManagerFactory::instance(); |
| 286 | if (cgroup_manager.isInit() && cpu_set) |
| 287 | { |
| 288 | DB::CpuSetPtr system_cpu_set = cgroup_manager.getSystemCpuSet(); |
| 289 | system_cpu_set->addTasks(tids); |
| 290 | } |
| 291 | LOG_DEBUG(&Poco::Logger::get("ThreadPool"), "clear thread for finalize : {}", ss.str()); |
| 292 | } |
| 293 | |
| 294 | threads.clear(); |
| 295 | } |
| 296 | |
| 297 | template <typename Thread> |
| 298 | size_t ThreadPoolImpl<Thread>::active() const |
no test coverage detected