The threaded program used in this ticket crashes intermittently. The error is sometimes "terminate called after throwing" and something "unwind called recursively". A sample stack trace is shown below.
#0 0x00000000 in ?? () #1 0xd254ece4 in __gxx_exception_cleanup (code=539406920, exc=0x2026b228) at /home/downloads/gcc/gcc-3.4.2/libstdc++-v3/libsupc++/eh_throw.cc:52 #2 0xd26bdab0 in _Unwind_DeleteException (exc=0x2026b228) at /home/downloads/gcc/gcc-3.4.2/gcc/unwind.inc:277 #3 0xd2548530 in __cxa_end_catch () at /home/downloads/gcc/gcc-3.4.2/libstdc++-v3/libsupc++/eh_catch.cc:119 #4 0x1000049c in thread_handler () #5 0xd004a410 in _pthread_body () from /usr/lib/libpthreads.a(shr_xpg5.o) #6 0x00000000 in ?? () #7 0x00000000 in ?? () Previous frame identical to this frame (corrupt stack?) To reproduce the bug, copy this program to "main.cpp" and compile it with "g++ - pthread main.cpp". Then, run the program with "while ./a.out do sleep 1; done". After a minute or so, the program will die. (It doesn't die every time, so that is why you need to run it in the loop.) ====================================================================== #include <pthread.h> #include <stdio.h> #include <unistd.h> #include <sys/timeb.h> #define NUM_THREADS 200 #define NUM_LOOPS 1000 pthread_mutexattr_t cs_attr; pthread_mutex_t cs; int cnt; void* thread_handler(void* idptr) { printf("thread_handler (start)\n"); for (int i=0; i<NUM_LOOPS; ++i) { try { throw "nothing"; } catch(...) { //pthread_mutex_lock(&cs); time_t now = time(0); struct tm now_tm; localtime_r(&now, &now_tm); //pthread_mutex_unlock(&cs); } } pthread_mutex_lock(&cs); ++cnt; pthread_mutex_unlock(&cs); printf("thread_handler (stop)\n"); return NULL; } int main(int argc, char** argv) { pthread_mutexattr_settype(&cs_attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&cs, &cs_attr); cnt = 0; for (int i=0; i<NUM_THREADS; ++i) { pthread_attr_t attr; int err = pthread_attr_init(&attr); if (err != 0) { printf("Could not initialize thread [errno=%d]\n", err); return 1; } err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (err != 0) { printf("Could not set detachable thread [errno=%d]\n", err); return 1; } pthread_t thread; err = pthread_create(&thread, &attr, thread_handler, (void*)NULL); if (err != 0) { printf("Could not create thread [errno=%d]\n", err); return 1; } } bool stop = false; while(!stop) { sleep(1); pthread_mutex_lock(&cs); stop = (cnt == NUM_THREADS); printf("*** cnt = %d\n", cnt); pthread_mutex_unlock(&cs); } return 0; } ====================================================================== gcc was configured as follows. configure --enable-threads=posix --prefix=/usr/local/gcc/gcc-3.x.x --enable-lang uages=c,c++ --disable-multilib -- Summary: terminate called after throwing - IOT/Abort trap (core dumped) Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: critical Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: askees at appfluent dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: powerpc-ibm-aix5.1.0.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18649