aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorAlexandre Oliva <oliva@adacore.com>2023-03-03 15:59:36 -0300
committerAlexandre Oliva <oliva@gnu.org>2023-03-03 16:06:44 -0300
commit21edd841611a97442a6b95e8ec7e91ff8fd3a451 (patch)
tree34a5e4e93347abfb81d949c23d0115bfc2e51c9d /libstdc++-v3/src
parentfdac2bea53bf5e7214352e2afd5542254c3156cb (diff)
downloadgcc-21edd841611a97442a6b95e8ec7e91ff8fd3a451.zip
gcc-21edd841611a97442a6b95e8ec7e91ff8fd3a451.tar.gz
gcc-21edd841611a97442a6b95e8ec7e91ff8fd3a451.tar.bz2
link pthread_join from std::thread ctor
Like pthread_create, pthread_join may fail to be statically linked in absent strong uses, so add to user code strong references to both when std::thread objects are created. for libstdc++-v3/ChangeLog PR libstdc++/104852 PR libstdc++/95989 PR libstdc++/52590 * include/bits/std_thread.h (thread::_M_thread_deps): New static implicitly-inline member function. (std::thread template ctor): Pass it to _M_start_thread. * src/c++11/thread.cc (thread::_M_start_thread): Name depend parameter, force it live on entry.
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/c++11/thread.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 2d5ffaf..c91f7b0 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -154,8 +154,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
void
- thread::_M_start_thread(_State_ptr state, void (*)())
+ thread::_M_start_thread(_State_ptr state, void (*depend)())
{
+ // Make sure it's not optimized out, not even with LTO.
+ asm ("" : : "rm" (depend));
+
if (!__gthread_active_p())
{
#if __cpp_exceptions
@@ -190,8 +193,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
void
- thread::_M_start_thread(__shared_base_type __b, void (*)())
+ thread::_M_start_thread(__shared_base_type __b, void (*depend)())
{
+ // Make sure it's not optimized out, not even with LTO.
+ asm ("" : : "rm" (depend));
+
auto ptr = __b.get();
// Create a reference cycle that will be broken in the new thread.
ptr->_M_this_ptr = std::move(__b);