[boost::thread] interrupt a future get boost::unknown_exception

[Windows XP, VC++ 10, boost 1.46]
When interrupt a future, the future.get() throw boost::unknown_exception,
Not boost::thread_interrupted.
Class boost::thread_interrupted should have a base class for current_exception_impl() to catch it ? or use BOOST_THROW_EXCEPTION in interruptible_wait) ?
///////////////
namespace boost
{
class thread_interrupted
{};
}
exception_ptr current_exception_impl()
{
try
{
throw;
}
catch(
exception_detail::clone_base & e )
{
return exception_ptr(e.clone());
}
................
catch(
std::exception & e )
{
return exception_detail::current_exception_unknown_std_exception(e);
}
catch(
boost::exception & e )
{
return exception_detail::current_exception_unknown_boost_exception(e);
}
catch(
... )
{
return exception_detail::current_exception_unknown_exception();
}
// unknown_exception//////////////////
ERROR: Throw in function (unknown)
Dynamic exception type: class boost::exception_detail::clone_impl<class boost::unknown_exception>
std::exception::what: Unknown exception
//code /////////////////////
#include

On Fri, 18 Mar 2011 11:30:11 +0100, 乔志强
[Windows XP, VC++ 10, boost 1.46] When interrupt a future, the future.get() throw boost::unknown_exception, Not boost::thread_interrupted.
Class boost::thread_interrupted should have a base class for current_exception_impl() to catch it ? or use BOOST_THROW_EXCEPTION in interruptible_wait) ?
/////////////// namespace boost { class thread_interrupted {}; }
exception_ptr current_exception_impl() { try { throw; } catch( exception_detail::clone_base & e ) { return exception_ptr(e.clone()); } ................ catch( std::exception & e ) { return exception_detail::current_exception_unknown_std_exception(e); } catch( boost::exception & e ) { return exception_detail::current_exception_unknown_boost_exception(e); } catch( ... ) { return exception_detail::current_exception_unknown_exception(); }
// unknown_exception////////////////// ERROR: Throw in function (unknown) Dynamic exception type: class boost::exception_detail::clone_impl<class boost::unknown_exception> std::exception::what: Unknown exception
//code ///////////////////// #include
#include #include using namespace boost::posix_time; using namespace boost; int main(int argc, char** argv) { boost::packaged_task<int> pt( [=]()->int { this_thread::sleep(seconds(1000)); return 0; } ); boost::unique_future<int> fi = pt.get_future(); boost::thread task(std::move(pt)); // launch task on a thread
task.interrupt();
try { int v = fi.get(); } catch (boost::exception& exc) { std::cerr << "ERROR: " << boost::diagnostic_information(exc) << std::endl; } }
Wow, boost-1.46 and lambdas, you're really working on the edge. Just to be sure it is a boost problem - can you make a classical function instead lambda and try with it? The test case seems nearly like one from the futures example - I really doubt it is a boost problem. I'd be glad to experiment with it yourself but my latest ubuntu has only gcc 4.4.5 and the lambdas said to be supported first from 4.5, plus I'd need to build 1.46 first, which takes quite a time on my nearly-netbook.. -- Slava

On Fri, Mar 18, 2011 at 3:30 AM, 乔志强
[Windows XP, VC++ 10, boost 1.46] When interrupt a future, the future.get() throw boost::unknown_exception, Not boost::thread_interrupted.
Class boost::thread_interrupted should have a base class for current_exception_impl() to catch it ? or use BOOST_THROW_EXCEPTION in interruptible_wait) ?
As far as I can tell, boost::thread always throws by calling boost::throw_exception which is sufficient for the boost::exception_ptr framework to work. Most likely, the unknown_exception is a result of attempting to copy a non-boost exception. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

AMDG On 03/18/2011 11:32 AM, Emil Dotchevski wrote:
On Fri, Mar 18, 2011 at 3:30 AM, 乔志强
wrote: [Windows XP, VC++ 10, boost 1.46] When interrupt a future, the future.get() throw boost::unknown_exception, Not boost::thread_interrupted.
Class boost::thread_interrupted should have a base class for current_exception_impl() to catch it ? or use BOOST_THROW_EXCEPTION in interruptible_wait) ? As far as I can tell, boost::thread always throws by calling boost::throw_exception which is sufficient for the boost::exception_ptr framework to work. Most likely, the unknown_exception is a result of attempting to copy a non-boost exception.
Actually, interruption_point() just uses throw. I checked both the pthread and win32 sources. In Christ, Steven Watanabe
participants (4)
-
Emil Dotchevski
-
Steven Watanabe
-
Viatcheslav.Sysoltsev@h-d-gmbh.de
-
乔志强