This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Are exception with gcc 2.95.2 thread-safe?
- To: "aurelien.cornet" <aurelien dot cornet at tms dot thomson-csf dot com>
- Subject: Re: Are exception with gcc 2.95.2 thread-safe?
- From: dvv at dvv dot ru (Dima Volodin)
- Date: Wed, 22 Mar 2000 19:04:18 GMT
- Cc: gcc at gcc dot gnu dot org
- Organization: Huh?
- References: <38D7612C.9FD0EADF@tms.thomson-csf.com>
On Tue, 21 Mar 2000 12:46:52 +0100, you wrote:
>The usual answer to this question is:
>
>The ANSI/ISO C++ Professional Programmer's Handbook (Danny Kalev)
>"In a multi-threading environment, exception handling should be
>thread-safe, but a single threading environment
>can implement exception handling in an non-thread-safe manner; this is
>implementation-dependent issue."
>
>I try the attached progam on Linux, Sun, Aix:
>In a main procedure, a try block creates a thread, sleep 2s (let the
>thread to be run), then throw an exception. We expected that this
>exception will be catched in main and the program terminates. But this
>program will never terminate and the result is:
>Thread has started
>Exception catched in thread
>
>Is it a bug? Can we use exception in a multi-threading program?
What compiler version and what compiler flags did you use? I tried your
program with g++ 2.95.2 in Solaris on both i386 and sparc and the output
in both cases was
Thread has started
exception catched in main
In both cases, the compiler was configured with --enable-threads=posix
and the program compiled as
g++ -D_REENTRANT main.C -lpthread
The canonical 2.95.2 Solaris sparc configuration uses these flags
automatically if you specify -pthreads in the command line.
BTW, I use exceptions in multi-threaded environment pretty heavily. My
only gripe is that exceptions don't propagate across Solaris libraries
calls (I wonder if it's possible to recompile all of them with gcc when
the sources become available). Other than that everything works the way
it's expected to work.
>Aurelien.
Cheers!
Dima