Description of problem: The following test program which demonstrates the problem dumps core with a "FATAL: exception not rethrown" if cancellation is not disabled around the use of cout. Note that cancellation type is DEFERRED. #include <unistd.h> #include <stdlib.h> #include <iostream> #include <pthread.h> using namespace std; struct A { A( int x=0): b(x) { cout << "constructor: " << b << "\n"; } ~A() {cout << "destructor: " << b << "\n"; } int b; }; void * thread( void * arg ) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0); try { A a; while (1) { cout << "going round round round\n"; for (int i = 0; i < 100000000; ++i) ; // pthread_testcancel(); } } catch (...) { cout << "caught ...\n"; throw ; } } int main() { pthread_t t; pthread_attr_t a; pthread_create( &t, 0, thread, 0 ); sleep(5); pthread_cancel(t); pthread_join( t, 0); } Version-Release number of selected component (if applicable): glibc-2.3.4-2.19 How reproducible: Always Steps to Reproduce: 1. g++ -g test.cc -lpthread 2. ./a.out 3. Actual results: constructor: 0 going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round FATAL: exception not rethrown going round round round Aborted (core dumped) Expected results: constructor: 0 going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round going round round round destructor: 0 caught ... Additional info: gdb) bt #0 0x00b847a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 #1 0x00bc47f5 in raise () from /lib/tls/libc.so.6 #2 0x00bc6199 in abort () from /lib/tls/libc.so.6 #3 0x0010afbd in unwind_cleanup () from /lib/tls/libpthread.so.0 #4 0x0033433c in _Unwind_DeleteException () from /lib/libgcc_s.so.1 #5 0x00405334 in __cxa_end_catch () from /usr/lib/libstdc++.so.6 #6 0x003dc295 in std::operator<< <std::char_traits<char> > () from /usr/lib/libstdc++.so.6 #7 0x08048a7c in thread (arg=0x0) at test.cc:24 #8 0x00106371 in start_thread () from /lib/tls/libpthread.so.0 #9 0x00c649be in clone () from /lib/tls/libc.so.6
Created attachment 126550 [details] test source
*** This bug has been marked as a duplicate of 118490 ***