Bug 186432 - c++ iostream does not work together with NPTL cancellation exception
c++ iostream does not work together with NPTL cancellation exception
Status: CLOSED DUPLICATE of bug 118490
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: glibc (Show other bugs)
4.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-03-23 10:45 EST by Morten Sylvest Olsen
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-03-24 06:24:29 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Morten Sylvest Olsen 2006-03-23 10:45:26 EST
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 10:45:26 EST
Created attachment 126550 [details]
test source
Comment 2 Jakub Jelinek 2006-03-24 06:24:29 EST

*** 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.