|
Boost Users : |
Subject: [Boost-users] [boost::thread] interrupt a future get boost::unknown_exception
From: ÇÇ־ǿ (qiaozhiqiang_at_[hidden])
Date: 2011-03-18 06:30:11
[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 <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/thread/future.hpp>
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;
}
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net