public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/18435] New: pthread_once hangs when init routine throws an exception
@ 2015-05-20  0:06 msebor at redhat dot com
  2015-05-20  0:09 ` [Bug nptl/18435] " msebor at redhat dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: msebor at redhat dot com @ 2015-05-20  0:06 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18435

            Bug ID: 18435
           Summary: pthread_once hangs when init routine throws an
                    exception
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at redhat dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

As discussed in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146, pthread_once
on at least ARM and PowerPC (but not x86_64) doesn't interact well with C++
exceptions thrown from the init routine.  The following test case demonstrates
the problem: it hangs in pthread_once until it's interrupted by SIGALRM.  The
test case runs successfully to completion on x86_64.

$ cat /home/remote/msebor/tmp/once.cc && g++ -Wall -g -lpthread
/home/remote/msebor/tmp/once.cc && gdb -batch -q -ex "catch signal SIGALRM" -ex
r -ex bt ./a.out
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static pthread_once_t once = PTHREAD_ONCE_INIT;
struct OnceException { };

static int niter;

static void init_routine (void) {
  if (niter < 2)
    throw OnceException ();
}

int main (void) {
  int result = 1;

  alarm (5);

  for (niter = 0; niter != 3; ++niter) {

    try {
      int rc = pthread_once (&once, init_routine);
      if (rc)
        fprintf (stderr, "pthread_once failed: %i (%s)\n",
                 rc, strerror (rc));

      if (niter < 2)
        fputs ("pthread_once unexpectedly returned without"
               " throwing an exception", stderr);
    }
    catch (OnceException) {
      if (1 < niter)
        fputs ("pthread_once unexpectedly threw", stderr);
      result = 0;
    }
    catch (...) {
      fputs ("pthread_once threw an unknown exception", stderr);
    }

    if (result)
      break;
  }

  return result;
}
Catchpoint 1 (signal SIGALRM)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power8/libthread_db.so.1".

Catchpoint 1 (signal SIGALRM), 0x00003fffb7f4f7bc in pthread_once () from
/lib64/power8/libpthread.so.0
#0  0x00003fffb7f4f7bc in pthread_once () from /lib64/power8/libpthread.so.0
#1  0x0000000010000c0c in main () at /home/remote/msebor/tmp/once.cc:25

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2021-03-04 14:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20  0:06 [Bug nptl/18435] New: pthread_once hangs when init routine throws an exception msebor at redhat dot com
2015-05-20  0:09 ` [Bug nptl/18435] " msebor at redhat dot com
2015-05-20 14:11 ` jwakely.gcc at gmail dot com
2015-05-20 14:29 ` bugdal at aerifal dot cx
2015-05-20 14:45 ` msebor at redhat dot com
2015-05-20 16:56 ` joseph at codesourcery dot com
2015-05-20 19:40 ` msebor at redhat dot com
2015-05-21  1:01 ` msebor at redhat dot com
2015-06-05  9:37 ` fweimer at redhat dot com
2015-07-01 20:09 ` cvs-commit at gcc dot gnu.org
2015-07-02  1:19 ` msebor at redhat dot com
2015-07-09 21:48 ` msebor at redhat dot com
2015-07-09 23:28 ` cvs-commit at gcc dot gnu.org
2021-03-04 14:23 ` jakub at redhat dot com
2021-03-04 14:28 ` jakub at redhat 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).