Boost logo

Boost :

From: Moore, Dave (dmoore_at_[hidden])
Date: 2002-08-05 10:01:41


>I've developed a way to support user exceptions in threads that I would
like
>to contribute to boost. In my opinion, it can replace/extend (in the
literal
>sense) the existing thread class (I also think the existing manor to
provide
>platform neutrality with ifndefs is unacceptable, but that is for a new
>message thread.).

If you look carefully, you'll see that the public -interface- to
Boost.Threads is homogenous and doesn't involve #ifdefs. The #ifdefs are
used to map this common interface onto three very different threading
platforms, pthreads, win32 threads, and Mac Carbon.

>
> Upon access to any (most -- debatable) of the public methods of the
> advanced_thread, a user exception may be thrown. Exceptions
> not listed to
> the class will cause std::bad_exception to be thrown (I
> believe that is
> appropriate). Of course, advanced_thread<void> does not provide
> getReturnValue () {or return_value () to follow STL naming}.

On which thread will the bad_exception be thrown? I'm not aware of a
mechanism that can catch an exception in another thread (the thread
encapsulated by your advanced_thread), and cause it to be thrown in another
thread...

>From your example, it seems like you may be passing information about thrown
exceptions during your call to testThread.getReturnValue(). Is this the
case? This approach may work for threads which are to be joined, but for
threads which are detached or not joined, I don't see a way for this
mechanism to work.

It seems to me that it's cleaner to let the user's main thread function
manage exceptions as it sees fit.

Regards,
Dave

>
> For instance:
>
> #include <boost/advanced_thread.hpp>
> #include <boost/bind.hpp>
>
> int testFunction () {
> throw 16;
> return 11;
> }
>
> int main () {
>
> typedef boost::advanced_thread<int,
> thread_exceptions<int, std::string>
> > Thread;
>
> try {
> Thread testThead (boost::bind (testFunction));
> int const returnValue = testThread.getReturnValue ();
> // implicit
> join
> }
> catch (int number) {
> std::cout << number << " was thrown!" << std::endl;
> }
> catch (std::bad_exception& exception) {
> std::cout << "An invalid exception was thrown by the
> thread user
> function. " << std::endl;
> }
> }
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk