Bug 186432 - c++ iostream does not work together with NPTL cancellation exception
Summary: c++ iostream does not work together with NPTL cancellation exception
Keywords:
Status: CLOSED DUPLICATE of bug 118490
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: glibc
Version: 4.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-03-23 15:45 UTC by Morten Sylvest Olsen
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-03-24 11:24:29 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
test source (884 bytes, text/plain)
2006-03-23 15:45 UTC, Morten Sylvest Olsen
no flags Details

Description Morten Sylvest Olsen 2006-03-23 15:45:26 UTC
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

Comment 1 Morten Sylvest Olsen 2006-03-23 15:45:26 UTC
Created attachment 126550 [details]
test source

Comment 2 Jakub Jelinek 2006-03-24 11:24:29 UTC

*** This bug has been marked as a duplicate of 118490 ***


Note You need to log in before you can comment on or make changes to this bug.