From: Jon Rafkind <workmin@ccs.neu.edu>
To: pthreads-win32@sourceware.org
Subject: pthreads and exceptions
Date: Mon, 07 Jan 2008 15:12:00 -0000 [thread overview]
Message-ID: <47824161.7000506@ccs.neu.edu> (raw)
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
reply other threads:[~2008-01-07 15:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47824161.7000506@ccs.neu.edu \
--to=workmin@ccs.neu.edu \
--cc=pthreads-win32@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).