Are exception with gcc 2.95.2 thread-safe?
Loren James Rittle
rittle@latour.rsch.comm.mot.com
Tue Mar 21 14:57:00 GMT 2000
> 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?
Your program is operating as it should in the three environments I
have easy access to: Solaris, Linux and FreeBSD. I suspect that there
is a reason why it isn't working for you.
Unfortunately, when you configure gcc, you have to explicitly inform
the process that you want thread safety! E.g.:
../egcs/configure --enable-threads
Then, you have to provide a non-portable-between-gcc-based-
development-environments switch during both compilation and linking:
On Linux and FreeBSD:
g++ -pthread main.C
On Solaris:
g++ -pthreads main.C
On OSF:
EITHER g++ -pthread main.C OR g++ -threads main.C
(but note that depending on which switch you give, your program will
link against a different set of libraries)
Don't ask me why you need to use different options... ;-)
Regards,
Loren
More information about the Gcc
mailing list