[Bug libstdc++/67791] [8/9/10/11 Regression] Crash using std::thread and iostream with dynamic loading of a shared library

2020-11-24 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67791

--- Comment #9 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:4bbd5d0c5fb2b7527938ad44a6d8a2f2ef8bbe12

commit r11-5315-g4bbd5d0c5fb2b7527938ad44a6d8a2f2ef8bbe12
Author: Jonathan Wakely 
Date:   Tue Nov 24 12:48:31 2020 +

libstdc++: Throw instead of segfaulting in std::thread constructor [PR
67791]

This turns a mysterious segfault into an exception with a more useful
message. If the exception isn't caught, the user sees this instead of
just a segfault:

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not
permitted
Aborted (core dumped)

libstdc++-v3/ChangeLog:

PR libstdc++/67791
* src/c++11/thread.cc (thread::_M_start_thread(_State_ptr, void
(*)())):
Check that gthreads is available before calling __gthread_create.

[Bug libstdc++/67791] [8/9/10/11 Regression] Crash using std::thread and iostream with dynamic loading of a shared library

2020-11-23 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67791

Jonathan Wakely  changed:

   What|Removed |Added

Summary|Crash using std::thread and |[8/9/10/11 Regression]
   |iostream with dynamic   |Crash using std::thread and
   |loading of a shared library |iostream with dynamic
   ||loading of a shared library
  Known to work||4.9.4
   Assignee|unassigned at gcc dot gnu.org  |redi at gcc dot gnu.org
 Status|NEW |ASSIGNED
  Known to fail||10.2.0, 11.0, 5.1.0, 8.4.0,
   ||9.3.0
   Target Milestone|--- |8.5

--- Comment #8 from Jonathan Wakely  ---
(In reply to Jonathan Wakely from comment #7)
> (In reply to nexyon from comment #4)
> > In any case std::thread should not
> > crash I guess, so just to fix that it would be necessary to check whether
> > the standard library was inizialized without threads.
> 
> We used to check for the pthread_create weak symbol, and throw an exception
> instead of crashing. Since the fix for PR libstdc++/61841 we don't check it,
> and crash instead of throwing. That should be fixed.

Marking as a regression, because GCC 4.9 printed this error instead of
crashing:

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)

That's better than segfaulting with no explanation.

I incorrectly assumed that the use of _create added for PR 61841 would
make checking __gthread_active_p unnecessary. As the examples here show, that's
not true. The program calls __gthread_active_p() before main() runs, and at
that time libpthread.so is not loaded. When libpthread.so is loaded later, it's
too late for __gthread_active_p to notice.