http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59869

            Bug ID: 59869
           Summary: [C++11] std::weak_ptr is thread-unsafe when built with
                    -fno-exceptions
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppluzhnikov at google dot com

Created attachment 31883
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31883&action=edit
test case

I will attach test case and a proposed patch shortly.

Using g++ (GCC) 4.9.0 20140116 (experimental)

g++ -std=c++11 test2.cc -pthread
for j in $(seq 1 100); do ./a.out &>/dev/null || break ; done

... works fine, but aborts when compiled with exceptions disabled:

g++ -std=c++11 test2.cc -pthread -fno-exceptions
 ./a.out
Aborted (core dumped)

The abort comes from here:

#0  0x00007ffff7021425 in __GI_raise (sig=<optimized out>) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff7024b8b in __GI_abort () at abort.c:91
#2  0x0000000000401807 in std::__throw_bad_weak_ptr () at
/gcc-svn-install/include/c++/4.9.0/bits/shared_ptr_base.h:78
#3  0x000000000040182a in
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock
(this=0x61c8d0) at
/gcc-svn-install/include/c++/4.9.0/bits/shared_ptr_base.h:240
#4  0x0000000000402443 in
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count
(this=0x7ffff67e8dd8, __r=...) at
/gcc-svn-install/include/c++/4.9.0/bits/shared_ptr_base.h:768
#5  0x0000000000402143 in std::__shared_ptr<int,
(__gnu_cxx::_Lock_policy)2>::__shared_ptr<int> (this=0x7ffff67e8dd0, __r=...)
at /gcc-svn-install/include/c++/4.9.0/bits/shared_ptr_base.h:877
#6  0x0000000000401def in std::shared_ptr<int>::shared_ptr<int>
(this=0x7ffff67e8dd0, __r=std::weak_ptr (expired, weak 1) 0x61c930) at
/gcc-svn-install/include/c++/4.9.0/bits/shared_ptr.h:249
#7  0x0000000000401b19 in std::weak_ptr<int>::lock (this=0x61c910) at
/gcc-svn-install/include/c++/4.9.0/bits/shared_ptr.h:502
#8  0x0000000000401318 in run_child_thread2 () at test2.cc:93
#9  0x0000000000403025 in std::_Bind_simple<void
(*())()>::_M_invoke<>(std::_Index_tuple<>) (this=0x629478) at
/gcc-svn-install/include/c++/4.9.0/functional:1700
#10 0x0000000000402f71 in std::_Bind_simple<void (*())()>::operator()()
(this=0x629478) at /gcc-svn-install/include/c++/4.9.0/functional:1688
#11 0x0000000000402ef0 in std::thread::_Impl<std::_Bind_simple<void (*())()>
>::_M_run() (this=0x629460) at /gcc-svn-install/include/c++/4.9.0/thread:115
#12 0x00007ffff7b46c78 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007ffff73b2e9a in start_thread (arg=0x7ffff67e9700) at
pthread_create.c:308
#14 0x00007ffff70df3fd in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:112

Reply via email to