1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/exception_ptr.hpp>
7 #include <boost/exception/get_error_info.hpp>
8 #include <boost/thread.hpp>
9 #include <boost/detail/atomic_count.hpp>
10 #include <boost/detail/lightweight_test.hpp>
12 typedef boost::error_info
<struct tag_answer
,int> answer
;
14 boost::detail::atomic_count
exc_count(0);
18 virtual boost::exception
,
19 virtual std::exception
32 ~err() BOOST_NOEXCEPT_OR_NOTHROW
39 err
& operator=( err
const & );
53 set_exception( boost::exception_ptr
const & e
)
55 boost::unique_lock
<boost::mutex
> lck (mux_
);
64 boost::unique_lock
<boost::mutex
> lck (mux_
);
67 rethrow_exception (exc_
);
73 boost::exception_ptr exc_
;
74 mutable boost::mutex mux_
;
75 mutable boost::condition_variable cond_
;
79 producer( future
& f
)
81 f
.set_exception (boost::copy_exception (err () << answer(42)));
88 boost::thread
thr (boost::bind (&producer
, boost::ref (f
)));
96 int const * ans
=boost::get_error_info
<answer
>(e
);
97 BOOST_TEST(ans
&& *ans
==42);
105 for( int i
=0; i
!=100; ++i
)
112 boost::thread_group grp
;
113 for( int i
=0; i
!=50; ++i
)
114 grp
.create_thread(&consume
);
121 boost::exception_ptr p
= boost::copy_exception(err());
124 rethrow_exception(p
);
141 BOOST_TEST(++exc_count
==1);
144 BOOST_TEST(!--exc_count
);
145 return boost::report_errors();