* pthreads and exceptions
@ 2008-01-07 15:12 Jon Rafkind
0 siblings, 0 replies; only message in thread
From: Jon Rafkind @ 2008-01-07 15:12 UTC (permalink / raw)
To: pthreads-win32
Hi,
I am experiencing an issue with pthreads 2.8.0 and c++ exceptions.
If main spawns thread A and thread A spawns thread B then thread A
throws an exception and tries to catch it, thread B will actually catch
it. I have tried libpthreadGC2.dll and libpthreadGCE2.dll but the
behavior is the same. Is there a way to make right the stack unwinding
behavior match that as on Linux?
Here is an example program which shows the behavior:
#include <stdio.h>
#include <exception>
#include <pthread.h>
using namespace std;
class Fex: public exception{
public:
Fex():exception(){}
};
void * d1_child( void * x ){
try{
int i;
printf( "d1 child running\n" );
for ( i = 0; i < 200000000; i++ ){
}
} catch ( const Fex & f ){
printf( "d1 child fex\n" );
}
printf( "d1 child done\n" );
}
void * d1( void * x ){
try{
pthread_t child;
pthread_create( &child, NULL, d1_child, NULL );
int i;
for ( i = 0; i < 100000000; i++ ){
}
printf( "d1 throwing fex\n" );
throw Fex();
pthread_join( child, NULL );
printf( "d1 joined child\n" );
} catch ( const Fex & f ){
printf( "d1 fex\n" );
}
printf( "d1 done\n" );
return NULL;
}
void * d2( void * x ){
try{
throw Fex();
} catch ( const Fex & f ){
printf( "d2 fex\n" );
}
return NULL;
}
int main(){
pthread_t n1, n2;
pthread_create( &n1, NULL, d1, NULL );
pthread_create( &n2, NULL, d2, NULL );
pthread_join( n1, NULL );
pthread_join( n2, NULL );
}
This will print
d2 fex
d1 child running
d1 throwing fex
d1 child fex
d1 child done
thanks,
jon
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-01-07 15:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-07 15:12 pthreads and exceptions Jon Rafkind
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).