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/config.hpp>
8 #if defined( BOOST_NO_EXCEPTIONS )
9 # error This program requires exception handling.
12 #include <boost/exception_ptr.hpp>
13 #include <boost/exception/get_error_info.hpp>
14 #include <boost/thread.hpp>
15 #include <boost/detail/atomic_count.hpp>
16 #include <boost/detail/lightweight_test.hpp>
18 typedef boost::error_info
<struct tag_answer
,int> answer
;
20 int const thread_count
= 100;
22 boost::detail::atomic_count
exc_count(0);
26 virtual boost::exception
,
27 virtual std::exception
40 ~err() BOOST_NOEXCEPT_OR_NOTHROW
47 err
& operator=( err
const & );
62 set_exception( boost::exception_ptr
const & e
)
64 boost::unique_lock
<boost::mutex
> lck(mux_
);
73 boost::unique_lock
<boost::mutex
> lck(mux_
);
76 rethrow_exception(exc_
);
82 boost::exception_ptr exc_
;
83 mutable boost::mutex mux_
;
84 mutable boost::condition_variable cond_
;
88 producer( future
& f
)
90 f
.set_exception(boost::copy_exception(err() << answer(42)));
97 boost::thread
thr(boost::bind(&producer
, boost::ref(f
)));
105 int const * ans
=boost::get_error_info
<answer
>(e
);
106 BOOST_TEST(ans
&& *ans
==42);
114 for( int i
=0; i
!=thread_count
; ++i
)
121 boost::thread_group grp
;
122 for( int i
=0; i
!=thread_count
; ++i
)
123 grp
.create_thread(&consume
);
130 boost::exception_ptr p
= boost::copy_exception(err() << answer(42));
133 rethrow_exception(p
);
150 BOOST_TEST(++exc_count
==1);
153 BOOST_TEST(!--exc_count
);
154 return boost::report_errors();