1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // Copyright (C) 2011 Vicente J. Botet Escriba 11 // 12 // Distributed under the Boost Software License, Version 1.0. (See accompanying 13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 14 15 // <boost/thread/future.hpp> 16 17 // class promise<R> 18 19 // void promise::set_exception_at_thread_exit(exception_ptr p); 20 21 #define BOOST_THREAD_VERSION 4 22 23 #include <boost/thread/future.hpp> 24 #include <boost/detail/lightweight_test.hpp> 25 #include <boost/static_assert.hpp> 26 27 template <typename T> 28 struct wrap 29 { wrapwrap30 wrap(T const& v) : 31 value(v) 32 { 33 } 34 T value; 35 36 }; 37 38 template <typename T> make_exception_ptr(T v)39 boost::exception_ptr make_exception_ptr(T v) 40 { 41 return boost::copy_exception(wrap<T> (v)); 42 } 43 44 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) func(boost::promise<int> p)45void func(boost::promise<int> p) 46 #else 47 boost::promise<int> p; 48 void func() 49 #endif 50 { 51 //p.set_exception(::make_exception_ptr(3)); 52 p.set_exception_at_thread_exit(::make_exception_ptr(3)); 53 } 54 main()55int main() 56 { 57 { 58 typedef int T; 59 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) 60 boost::promise<T> p; 61 boost::future<T> f = p.get_future(); 62 boost::thread(func, boost::move(p)).detach(); 63 #else 64 boost::future<T> f = p.get_future(); 65 boost::thread(func).detach(); 66 #endif 67 try 68 { 69 f.get(); 70 BOOST_TEST(false); 71 } 72 catch (::wrap<int> i) 73 { 74 BOOST_TEST(i.value == 3); 75 } 76 catch (...) 77 { 78 BOOST_TEST(false); 79 } 80 } 81 { 82 typedef int T; 83 boost::promise<T> p2; 84 boost::future<T> f = p2.get_future(); 85 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) 86 boost::thread(func, boost::move(p2)).detach(); 87 #else 88 p = boost::move(p2); 89 boost::thread(func).detach(); 90 #endif 91 try 92 { 93 f.get(); 94 BOOST_TEST(false); 95 } 96 catch (::wrap<int> i) 97 { 98 BOOST_TEST(i.value == 3); 99 } 100 catch (...) 101 { 102 BOOST_TEST(false); 103 } 104 } 105 return boost::report_errors(); 106 } 107 108