MCPcopy Create free account
hub / github.com/ByConity/ByConity / finalize

Method finalize

src/Common/ThreadPool.cpp:255–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253
254template <typename Thread>
255void 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
297template <typename Thread>
298size_t ThreadPoolImpl<Thread>::active() const

Callers 1

StatusFileMethod · 0.45

Calls 12

isInitMethod · 0.80
getSystemCpuSetMethod · 0.80
getFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
joinMethod · 0.45
emplace_backMethod · 0.45
gettidMethod · 0.45
emptyMethod · 0.45
addTasksMethod · 0.45
strMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected