This is a small optimisation to avoid atomic updates to the ref-counts. I have a bigger change in the pipeline for the trunk, but this is an incremental improvement and is safe for gcc-5-branch.
Tested powerpc64le-linux, committed to trunk.
commit 6cd552bb41661fc48111b7162641d4e8b4c85404 Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Mar 12 13:23:23 2015 +0000 PR libstdc++/65393 * src/c++11/thread.cc (thread::_M_make_thread): Replace shared_ptr copies with moves. diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc index 954f267..906cafa 100644 --- a/libstdc++-v3/src/c++11/thread.cc +++ b/libstdc++-v3/src/c++11/thread.cc @@ -92,7 +92,7 @@ namespace std _GLIBCXX_VISIBILITY(default) std::terminate(); } - return 0; + return nullptr; } } @@ -137,18 +137,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __throw_system_error(int(errc::operation_not_permitted)); #endif - _M_start_thread(__b, nullptr); + _M_start_thread(std::move(__b), nullptr); } void thread::_M_start_thread(__shared_base_type __b, void (*)()) { - __b->_M_this_ptr = __b; + auto ptr = __b.get(); + ptr->_M_this_ptr = std::move(__b); int __e = __gthread_create(&_M_id._M_thread, - &execute_native_thread_routine, __b.get()); + &execute_native_thread_routine, ptr); if (__e) { - __b->_M_this_ptr.reset(); + ptr->_M_this_ptr.reset(); __throw_system_error(__e); } }