Unix Programming - is throwing an exception MT safer?`

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2004 > is throwing an exception MT safer?`





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author is throwing an exception MT safer?`
Shea Martin

2004-02-14, 9:33 am

I just read (http://linuxselfhelp.com/HOWTO/SMP-HOWTO-2.html) that throwing
exceptions is now thread safe. They don't mention which compilers specifically
cause thei problem though, and there is no date on the article. Thus I have the
following questions, regarding linux x86, solaris SPARC, and pthreads:

*is throwing an exception safe in g++/linux/pthreads?
*is throwing an an exception safe in CC/solaris/pthreads?

If no, is putting a mutex in the constructor of the class I am throwing a
suitable work around? Or mutex the throw statement?

If your answer is version specific, please specify which versions. Thanks.

~S
Seongbae Park

2004-02-16, 6:33 pm

In article <BMxXb.503755$ts4.289516@pd7tw3no>, Shea Martin wrote:
> I just read (http://linuxselfhelp.com/HOWTO/SMP-HOWTO-2.html) that throwing
> exceptions is now thread safe. They don't mention which compilers specifically
> cause thei problem though, and there is no date on the article. Thus I have the
> following questions, regarding linux x86, solaris SPARC, and pthreads:
>
> *is throwing an exception safe in g++/linux/pthreads?
> *is throwing an an exception safe in CC/solaris/pthreads?
>
> If no, is putting a mutex in the constructor of the class I am throwing a
> suitable work around? Or mutex the throw statement?
>
> If your answer is version specific, please specify which versions. Thanks.
>
> ~S


From the C++ User's Guide of SunOne Studio 8 C++:

11.2 Using Exceptions in a Multithreaded Program

The current exception-handling implementation is safe for
multithreading; exceptions in one thread do not interfere with
exceptions in other threads. However, you cannot use exceptions to
communicate across threads; an exception thrown from one thread cannot
be caught in another.

Each thread can set its own terminate() or unexpected() function.
Calling set_terminate() or set_unexpected() in one thread affects only
the exceptions in that thread. The default function for terminate() is
abort() for the main thread, and thr_exit() for other threads (see
Section 8.2, Specifying Runtime Errors).

Note - Thread cancellation (pthread_cancel(3T)) results in the
destruction of automatic (local nonstatic) objects on the stack. When
a thread is cancelled, the execution of local destructors is
interleaved with the execution of cleanup routines that the user has
registered with pthread_cleanup_push(). The local objects for
functions called after a particular cleanup routine is registered are
destroyed before that routine is executed.

Most or all of the above applies to
Sun Workshop 4.1, Sun Workshop 4.2, Sun Workshop 5,
Forte Developer 6 and Forte Developer 7 -
all Sun C++ compilers as far as I remember.

Seongbae
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com