From 909e306757b2da405daed2e0838e11b65e033c1a Mon Sep 17 00:00:00 2001 From: kulikov Date: Fri, 28 Nov 2025 00:32:45 +0300 Subject: Use generic thread-local value for kernel/groupattrs, crash context and eventlog scope - fix StdThreadLocalImpl -- make static state refcounted, there is no guarantee that static fields will outlive threads or TThreadLocalValues; - replace thread local values to generic local storage value in some places; - call runtime Init and replace local values factory; - don't disable NCurrentThreadEventlog for ytxx runtime, it should now work; - ensure generic local storage values are allocated after runtime init; - use function-scope static variables to prevent issues with order of construction and destruction; - basesearch now almost works with coroutines (with NProfile disabled). commit_hash:7fde81591b0dbc3a53b8d1cb11bb96930a2e9a80 --- library/cpp/threading/thread_local/generic.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'library/cpp/threading/thread_local/generic.cpp') diff --git a/library/cpp/threading/thread_local/generic.cpp b/library/cpp/threading/thread_local/generic.cpp index 41e1b381672..79161a846da 100644 --- a/library/cpp/threading/thread_local/generic.cpp +++ b/library/cpp/threading/thread_local/generic.cpp @@ -14,17 +14,29 @@ namespace { NThreading::TThreadLocalValue Data_; }; - NThreading::TGenericLocalStorageFactory genericLocalStorageFactory = []() { - return MakeHolder(); - }; + std::atomic& DefaultFactoryUsageCounter() { + static std::atomic v; + return v; + } + + auto& genericLocalStorageFactory() { + static NThreading::TGenericLocalStorageFactory factory = [] { + DefaultFactoryUsageCounter() += 1; + return MakeHolder(); + }; + + return factory; + } } namespace NThreading { void SetGenericLocalStorageFactory(TGenericLocalStorageFactory factory) { - genericLocalStorageFactory = factory; + Y_ENSURE(DefaultFactoryUsageCounter() == 0, "There are some thread local values allocated with default factory"); + + genericLocalStorageFactory() = factory; } THolder MakeGenericLocalStorage() { - return genericLocalStorageFactory(); + return genericLocalStorageFactory()(); } } -- cgit v1.3