[gcc(refs/users/aoliva/heads/testme)] link pthread_join from std::thread ctor

Alexandre Oliva aoliva@gcc.gnu.org
Fri Mar 3 05:23:50 GMT 2023


https://gcc.gnu.org/g:45fd40a3a15f083ea13e515e8b6ab62189736df8

commit 45fd40a3a15f083ea13e515e8b6ab62189736df8
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Fri Mar 3 02:14:53 2023 -0300

    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
    
            * include/bits/std_thread.h (std::thread ctor): Add strong
            reference to pthread_join.
            * testsuite/30_threads/jthread/95989.cc: Drop extraneous join
            call.
    
    Change-Id: I6c40875f7f7c2c08278f950f23e3b7163dd71c5c
    TN: W127-055

Diff:
---
 libstdc++-v3/include/bits/std_thread.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/include/bits/std_thread.h b/libstdc++-v3/include/bits/std_thread.h
index adbd3928ff7..a504a0b48ed 100644
--- a/libstdc++-v3/include/bits/std_thread.h
+++ b/libstdc++-v3/include/bits/std_thread.h
@@ -145,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #ifdef GTHR_ACTIVE_PROXY
 	// Create a reference to pthread_create, not just the gthr weak symbol.
 	auto __depend = reinterpret_cast<void(*)()>(&pthread_create);
+	static auto __attribute__((__unused__)) __depend_join = &pthread_join;
 #else
 	auto __depend = nullptr;
 #endif


More information about the Libstdc++-cvs mailing list