public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59869] New: [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions
@ 2014-01-18  2:48 ppluzhnikov at google dot com
  2014-01-18 11:40 ` [Bug libstdc++/59869] " redi at gcc dot gnu.org
  2014-01-18 16:58 ` ppluzhnikov at google dot com
  0 siblings, 2 replies; 3+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-18  2:48 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/59869] [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions
  2014-01-18  2:48 [Bug c++/59869] New: [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions ppluzhnikov at google dot com
@ 2014-01-18 11:40 ` redi at gcc dot gnu.org
  2014-01-18 16:58 ` ppluzhnikov at google dot com
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-18 11:40 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
What do you mean by thread-unsafe?  I agree it aborts, but there are no race
conditions or undefined behaviour.

Isn't this PR 59656?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/59869] [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions
  2014-01-18  2:48 [Bug c++/59869] New: [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions ppluzhnikov at google dot com
  2014-01-18 11:40 ` [Bug libstdc++/59869] " redi at gcc dot gnu.org
@ 2014-01-18 16:58 ` ppluzhnikov at google dot com
  1 sibling, 0 replies; 3+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-18 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
> What do you mean by thread-unsafe?

I mean that a multithreaded program built with -fno-exceptions and using
weak_ptr may abort through no fault of its own, and that renders weak_ptr
unusable in such programs.

*** This bug has been marked as a duplicate of bug 59656 ***


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-18 16:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-18  2:48 [Bug c++/59869] New: [C++11] std::weak_ptr is thread-unsafe when built with -fno-exceptions ppluzhnikov at google dot com
2014-01-18 11:40 ` [Bug libstdc++/59869] " redi at gcc dot gnu.org
2014-01-18 16:58 ` ppluzhnikov at google dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).