This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nptl/18435] New: pthread_once hangs when init routine throws an exception
- From: "msebor at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 20 May 2015 00:06:25 +0000
- Subject: [Bug nptl/18435] New: pthread_once hangs when init routine throws an exception
- Auto-submitted: auto-generated
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.