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

Method finalize

src/Common/ThreadPool.cpp:562–591  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560
561template <typename Thread>
562void ThreadPoolImpl<Thread>::finalize()
563{
564 {
565 std::lock_guard lock(mutex);
566 shutdown = true;
567
568 /// scheduleImpl doesn't check for shutdown outside the critical section,
569 /// so we set remaining_pool_capacity to a large negative value
570 /// (e.g., -MAX_THEORETICAL_THREAD_COUNT) to signal that no new threads are needed.
571 /// This effectively prevents any new threads from being started during shutdown.
572 remaining_pool_capacity.store(-MAX_THEORETICAL_THREAD_COUNT, std::memory_order_relaxed);
573
574 /// Disable thread self-removal from `threads`. Otherwise, if threads remove themselves,
575 /// the thread.join() operation will fail later in this function.
576 threads_remove_themselves = false;
577
578 /// Wake up all idle threads so they can see shutdown and exit gracefully.
579 wakeUpAllIdleThreadsNoLock();
580 }
581
582 /// Join all threads before clearing the list
583 for (auto& thread_ptr : threads)
584 {
585 if (thread_ptr)
586 thread_ptr->join();
587 }
588
589 // now it's safe to clear the threads
590 threads.clear();
591}
592
593template <typename Thread>
594void ThreadPoolImpl<Thread>::addOnDestroyCallback(OnDestroyCallback && callback)

Callers 15

StatusFileMethod · 0.45
saveMethod · 0.45
childSignalHandlerFunction · 0.45
signalHandlerFunction · 0.45
terminate_handlerFunction · 0.45
sendMethod · 0.45
shutdownMethod · 0.45
dumpBlockToJSONFunction · 0.45
executeDirectMethod · 0.45
addMethod · 0.45
fixIfBrokenMethod · 0.45

Calls 3

storeMethod · 0.45
joinMethod · 0.45
clearMethod · 0.45

Tested by 1

TESTFunction · 0.36