From f26b401bceaf9d119e31b45568c41188def5176c Mon Sep 17 00:00:00 2001 From: babenko Date: Wed, 1 Jul 2026 10:01:53 +0300 Subject: Reliable on-demand construction of TThreadLockTracker instance commit_hash:39506fb1534ae2d5c5dfe509c9d95a7f74c2aa18 --- library/cpp/yt/threading/rw_spin_lock.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'library/cpp/yt/threading/rw_spin_lock.cpp') diff --git a/library/cpp/yt/threading/rw_spin_lock.cpp b/library/cpp/yt/threading/rw_spin_lock.cpp index efc0e90167a..3150c1aa132 100644 --- a/library/cpp/yt/threading/rw_spin_lock.cpp +++ b/library/cpp/yt/threading/rw_spin_lock.cpp @@ -41,7 +41,8 @@ void TUncheckedReaderWriterSpinLock::AcquireWriterSlow() noexcept namespace { -// NB: Reading this after destruction is UB, but we can't deal with Static Initialization Order Fiasco in any other feasible way :( +// NB: Reading this after destruction is UB, but we can't deal with +// Static Initialization Order Fiasco in any other feasible way :( YT_DEFINE_THREAD_LOCAL(bool, ThreadLockTrackerDestroyed, false); class TThreadLockTracker @@ -61,13 +62,17 @@ public: ~TThreadLockTracker() { ThreadLockTrackerDestroyed() = true; - }; + } private: THashSet ThreadLocksAcquired_; }; -YT_DEFINE_THREAD_LOCAL(TThreadLockTracker, ThreadLockTracker); +YT_PREVENT_TLS_CACHING static TThreadLockTracker& ThreadLockTracker() +{ + static thread_local TThreadLockTracker Instance; + return Instance; +} } // namespace -- cgit v1.3