Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
thread_logger_init.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
37
38namespace {
39
47void register_shutdown_handler() {
48 // Register the shutdown handler
49 // Since this runs early, it will be called late during shutdown (LIFO order)
50 // This ensures is_shutting_down() returns true during static destruction
52}
53
54#if defined(__GNUC__) || defined(__clang__)
55// GCC/Clang: Use constructor attribute with priority 101
56// Priority 101 runs after CRT initialization (65535-100) but before
57// user constructors (default priority is 65535)
58// Lower numbers = earlier execution, so 101 is very early
59__attribute__((constructor(101)))
60static void early_register_shutdown_handler() {
61 register_shutdown_handler();
62}
63
64#elif defined(_MSC_VER)
65// MSVC: Use CRT initialization section
66// .CRT$XCU runs during C++ static initialization, early in the process
67
68#pragma section(".CRT$XCU", read)
69
70// Function pointer that will be called during CRT initialization
71static void __cdecl msvc_register_shutdown_handler() {
72 register_shutdown_handler();
73}
74
75// Place the function pointer in the .CRT$XCU section
76// This causes it to be called during CRT initialization
77__declspec(allocate(".CRT$XCU"))
78static void (__cdecl *p_msvc_register_shutdown_handler)() = msvc_register_shutdown_handler;
79
80#else
81// Fallback for other compilers: Use static initialization
82// This is less reliable for initialization order but better than nothing
83namespace {
84struct ShutdownHandlerRegistrar {
85 ShutdownHandlerRegistrar() {
86 register_shutdown_handler();
87 }
88};
89static ShutdownHandlerRegistrar shutdown_handler_registrar;
90}
91#endif
92
93} // anonymous namespace
static void prepare_shutdown()
Prepare for process shutdown.
Internal logging interface for the thread system.