Boost logo

Boost :

Subject: [boost] [thread] 5351 interrupt a future get boost::unknown_exception
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-12-10 20:41:51


Hi,

I have reached to compile the example with some variants. See the
attached file in http://svn.boost.org/trac/boost/ticket/5351.

It seems the problem comes from the fact that packaged_task catch every
exception

            void do_run()
             {
                 try
                 {
                     this->mark_finished_with_result(f());
                 }
                 catch(...)
                 {
                     this->mark_exceptional_finish();
                 }
             }

and store it to rethrow in the wait() function using
boost::rethrow_exception.

                 if(rethrow&& exception)
                 {
                     boost::rethrow_exception(exception);
                 }

As thread_interrupted doesn't inherits from std/boost::exception the
thrown exception is translated as boost::unknown_exception.

A solution could be to catch specifically thread_interrupted and store
this fact.

                 catch(thread_interrupted& it)
                 {
                     this->mark_interrupted_finish();
                 }

             void mark_interrupted_finish()
             {
                 boost::lock_guard<boost::mutex> lock(mutex);
                 thread_was_interrupted=true;
                 mark_finished_internal();
             }

When wait is called, a test if the thread has been interrupted is done
so that the exception thread_interrupted is thrown.

                 if(rethrow && thread_was_interrupted)
                 {
                     throw boost::thread_interrupted();
                 }

The single problem I see is that the this new exception doesn't contains
from where the initial thread_interrupted was thrown.

Could the interested parties inspect the patch attached to
http://svn.boost.org/trac/boost/ticket/5351 and check it, please?
Is there something I forgot or a simple or more robust way to solve this
missing feature?

Best,
Vicente


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