aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/src/thread.cpp
diff options
context:
space:
mode:
authormikhnenko <mikhnenko@yandex-team.com>2023-10-14 13:00:57 +0300
committermikhnenko <mikhnenko@yandex-team.com>2023-10-14 13:22:30 +0300
commit4371a757495f375ca7c5b1730f4e9f741a71ec40 (patch)
treebe8f3405e7b0534d29bfb8eec493c0dbe108adc5 /contrib/libs/cxxsupp/libcxx/src/thread.cpp
parentecb10029a72bb21f92858ff3c0d76c8f255cf4ba (diff)
downloadydb-4371a757495f375ca7c5b1730f4e9f741a71ec40.tar.gz
Update libc++ to 1 May 2022 639b9618f46d75f4dabd2082b3f6ba8433c287bf
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src/thread.cpp')
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/thread.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/thread.cpp b/contrib/libs/cxxsupp/libcxx/src/thread.cpp
index 0734659d2d..ce2822dbac 100644
--- a/contrib/libs/cxxsupp/libcxx/src/thread.cpp
+++ b/contrib/libs/cxxsupp/libcxx/src/thread.cpp
@@ -115,8 +115,13 @@ sleep_for(const chrono::nanoseconds& ns)
__thread_specific_ptr<__thread_struct>&
__thread_local_data()
{
- static __thread_specific_ptr<__thread_struct> __p;
- return __p;
+ // Even though __thread_specific_ptr's destructor doesn't actually destroy
+ // anything (see comments there), we can't call it at all because threads may
+ // outlive the static variable and calling its destructor means accessing an
+ // object outside of its lifetime, which is UB.
+ alignas(__thread_specific_ptr<__thread_struct>) static char __b[sizeof(__thread_specific_ptr<__thread_struct>)];
+ static __thread_specific_ptr<__thread_struct>* __p = new (__b) __thread_specific_ptr<__thread_struct>();
+ return *__p;
}
// __thread_struct_imp