|
libstdc++
|
00001 // <future> -*- C++ -*- 00002 00003 // Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/future 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 #ifndef _GLIBCXX_FUTURE 00030 #define _GLIBCXX_FUTURE 1 00031 00032 #pragma GCC system_header 00033 00034 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00035 # include <bits/c++0x_warning.h> 00036 #else 00037 00038 #include <functional> 00039 #include <memory> 00040 #include <mutex> 00041 #include <thread> 00042 #include <condition_variable> 00043 #include <system_error> 00044 #include <exception> 00045 #include <atomic> 00046 #include <bits/functexcept.h> 00047 00048 namespace std _GLIBCXX_VISIBILITY(default) 00049 { 00050 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00051 00052 /** 00053 * @defgroup futures Futures 00054 * @ingroup concurrency 00055 * 00056 * Classes for futures support. 00057 * @{ 00058 */ 00059 00060 /// Error code for futures 00061 enum class future_errc 00062 { 00063 future_already_retrieved = 1, 00064 promise_already_satisfied, 00065 no_state, 00066 broken_promise 00067 }; 00068 00069 /// Specialization. 00070 template<> 00071 struct is_error_code_enum<future_errc> : public true_type { }; 00072 00073 /// Points to a statically-allocated object derived from error_category. 00074 const error_category& 00075 future_category() noexcept; 00076 00077 /// Overload for make_error_code. 00078 inline error_code 00079 make_error_code(future_errc __errc) noexcept 00080 { return error_code(static_cast<int>(__errc), future_category()); } 00081 00082 /// Overload for make_error_condition. 00083 inline error_condition 00084 make_error_condition(future_errc __errc) noexcept 00085 { return error_condition(static_cast<int>(__errc), future_category()); } 00086 00087 /** 00088 * @brief Exception type thrown by futures. 00089 * @ingroup exceptions 00090 */ 00091 class future_error : public logic_error 00092 { 00093 error_code _M_code; 00094 00095 public: 00096 explicit future_error(error_code __ec) 00097 : logic_error("std::future_error"), _M_code(__ec) 00098 { } 00099 00100 virtual ~future_error() noexcept; 00101 00102 virtual const char* 00103 what() const noexcept; 00104 00105 const error_code& 00106 code() const noexcept { return _M_code; } 00107 }; 00108 00109 // Forward declarations. 00110 template<typename _Res> 00111 class future; 00112 00113 template<typename _Res> 00114 class shared_future; 00115 00116 template<typename _Signature> 00117 class packaged_task; 00118 00119 template<typename _Res> 00120 class promise; 00121 00122 /// Launch code for futures 00123 enum class launch 00124 { 00125 async = 1, 00126 deferred = 2 00127 }; 00128 00129 constexpr launch operator&(launch __x, launch __y) 00130 { 00131 return static_cast<launch>( 00132 static_cast<int>(__x) & static_cast<int>(__y)); 00133 } 00134 00135 constexpr launch operator|(launch __x, launch __y) 00136 { 00137 return static_cast<launch>( 00138 static_cast<int>(__x) | static_cast<int>(__y)); 00139 } 00140 00141 constexpr launch operator^(launch __x, launch __y) 00142 { 00143 return static_cast<launch>( 00144 static_cast<int>(__x) ^ static_cast<int>(__y)); 00145 } 00146 00147 constexpr launch operator~(launch __x) 00148 { return static_cast<launch>(~static_cast<int>(__x)); } 00149 00150 inline launch& operator&=(launch& __x, launch __y) 00151 { return __x = __x & __y; } 00152 00153 inline launch& operator|=(launch& __x, launch __y) 00154 { return __x = __x | __y; } 00155 00156 inline launch& operator^=(launch& __x, launch __y) 00157 { return __x = __x ^ __y; } 00158 00159 /// Status code for futures 00160 enum class future_status 00161 { 00162 ready, 00163 timeout, 00164 deferred 00165 }; 00166 00167 template<typename _Fn, typename... _Args> 00168 future<typename result_of<_Fn(_Args...)>::type> 00169 async(launch __policy, _Fn&& __fn, _Args&&... __args); 00170 00171 template<typename _FnCheck, typename _Fn, typename... _Args> 00172 struct __async_sfinae_helper 00173 { 00174 typedef future<typename result_of<_Fn(_Args...)>::type> type; 00175 }; 00176 00177 template<typename _Fn, typename... _Args> 00178 struct __async_sfinae_helper<launch, _Fn, _Args...> 00179 { }; 00180 00181 template<typename _Fn, typename... _Args> 00182 typename 00183 __async_sfinae_helper<typename decay<_Fn>::type, _Fn, _Args...>::type 00184 async(_Fn&& __fn, _Args&&... __args); 00185 00186 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ 00187 && (ATOMIC_INT_LOCK_FREE > 1) 00188 00189 /// Base class and enclosing scope. 00190 struct __future_base 00191 { 00192 /// Base class for results. 00193 struct _Result_base 00194 { 00195 exception_ptr _M_error; 00196 00197 _Result_base(const _Result_base&) = delete; 00198 _Result_base& operator=(const _Result_base&) = delete; 00199 00200 // _M_destroy() allows derived classes to control deallocation 00201 virtual void _M_destroy() = 0; 00202 00203 struct _Deleter 00204 { 00205 void operator()(_Result_base* __fr) const { __fr->_M_destroy(); } 00206 }; 00207 00208 protected: 00209 _Result_base(); 00210 virtual ~_Result_base(); 00211 }; 00212 00213 /// Result. 00214 template<typename _Res> 00215 struct _Result : _Result_base 00216 { 00217 private: 00218 typedef alignment_of<_Res> __a_of; 00219 typedef aligned_storage<sizeof(_Res), __a_of::value> __align_storage; 00220 typedef typename __align_storage::type __align_type; 00221 00222 __align_type _M_storage; 00223 bool _M_initialized; 00224 00225 public: 00226 _Result() noexcept : _M_initialized() { } 00227 00228 ~_Result() 00229 { 00230 if (_M_initialized) 00231 _M_value().~_Res(); 00232 } 00233 00234 // Return lvalue, future will add const or rvalue-reference 00235 _Res& 00236 _M_value() noexcept { return *static_cast<_Res*>(_M_addr()); } 00237 00238 void 00239 _M_set(const _Res& __res) 00240 { 00241 ::new (_M_addr()) _Res(__res); 00242 _M_initialized = true; 00243 } 00244 00245 void 00246 _M_set(_Res&& __res) 00247 { 00248 ::new (_M_addr()) _Res(std::move(__res)); 00249 _M_initialized = true; 00250 } 00251 00252 private: 00253 void _M_destroy() { delete this; } 00254 00255 void* _M_addr() noexcept { return static_cast<void*>(&_M_storage); } 00256 }; 00257 00258 /// A unique_ptr based on the instantiating type. 00259 template<typename _Res> 00260 using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>; 00261 00262 /// Result_alloc. 00263 template<typename _Res, typename _Alloc> 00264 struct _Result_alloc final : _Result<_Res>, _Alloc 00265 { 00266 typedef typename allocator_traits<_Alloc>::template 00267 rebind_alloc<_Result_alloc> __allocator_type; 00268 00269 explicit 00270 _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _Alloc(__a) 00271 { } 00272 00273 private: 00274 void _M_destroy() 00275 { 00276 typedef allocator_traits<__allocator_type> __traits; 00277 __allocator_type __a(*this); 00278 __traits::destroy(__a, this); 00279 __traits::deallocate(__a, this, 1); 00280 } 00281 }; 00282 00283 template<typename _Res, typename _Allocator> 00284 static _Ptr<_Result_alloc<_Res, _Allocator>> 00285 _S_allocate_result(const _Allocator& __a) 00286 { 00287 typedef _Result_alloc<_Res, _Allocator> __result_type; 00288 typedef allocator_traits<typename __result_type::__allocator_type> 00289 __traits; 00290 typename __traits::allocator_type __a2(__a); 00291 __result_type* __p = __traits::allocate(__a2, 1); 00292 __try 00293 { 00294 __traits::construct(__a2, __p, __a); 00295 } 00296 __catch(...) 00297 { 00298 __traits::deallocate(__a2, __p, 1); 00299 __throw_exception_again; 00300 } 00301 return _Ptr<__result_type>(__p); 00302 } 00303 00304 00305 /// Base class for state between a promise and one or more 00306 /// associated futures. 00307 class _State_base 00308 { 00309 typedef _Ptr<_Result_base> _Ptr_type; 00310 00311 _Ptr_type _M_result; 00312 mutex _M_mutex; 00313 condition_variable _M_cond; 00314 atomic_flag _M_retrieved; 00315 once_flag _M_once; 00316 00317 public: 00318 _State_base() noexcept : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT) { } 00319 _State_base(const _State_base&) = delete; 00320 _State_base& operator=(const _State_base&) = delete; 00321 virtual ~_State_base(); 00322 00323 _Result_base& 00324 wait() 00325 { 00326 _M_run_deferred(); 00327 unique_lock<mutex> __lock(_M_mutex); 00328 _M_cond.wait(__lock, [&] { return _M_ready(); }); 00329 return *_M_result; 00330 } 00331 00332 template<typename _Rep, typename _Period> 00333 future_status 00334 wait_for(const chrono::duration<_Rep, _Period>& __rel) 00335 { 00336 unique_lock<mutex> __lock(_M_mutex); 00337 if (_M_cond.wait_for(__lock, __rel, [&] { return _M_ready(); })) 00338 return future_status::ready; 00339 return future_status::timeout; 00340 } 00341 00342 template<typename _Clock, typename _Duration> 00343 future_status 00344 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) 00345 { 00346 unique_lock<mutex> __lock(_M_mutex); 00347 if (_M_cond.wait_until(__lock, __abs, [&] { return _M_ready(); })) 00348 return future_status::ready; 00349 return future_status::timeout; 00350 } 00351 00352 void 00353 _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false) 00354 { 00355 bool __set = __ignore_failure; 00356 // all calls to this function are serialized, 00357 // side-effects of invoking __res only happen once 00358 call_once(_M_once, &_State_base::_M_do_set, this, ref(__res), 00359 ref(__set)); 00360 if (!__set) 00361 __throw_future_error(int(future_errc::promise_already_satisfied)); 00362 } 00363 00364 void 00365 _M_break_promise(_Ptr_type __res) 00366 { 00367 if (static_cast<bool>(__res)) 00368 { 00369 error_code __ec(make_error_code(future_errc::broken_promise)); 00370 __res->_M_error = copy_exception(future_error(__ec)); 00371 { 00372 lock_guard<mutex> __lock(_M_mutex); 00373 _M_result.swap(__res); 00374 } 00375 _M_cond.notify_all(); 00376 } 00377 } 00378 00379 // Called when this object is passed to a future. 00380 void 00381 _M_set_retrieved_flag() 00382 { 00383 if (_M_retrieved.test_and_set()) 00384 __throw_future_error(int(future_errc::future_already_retrieved)); 00385 } 00386 00387 template<typename _Res, typename _Arg> 00388 struct _Setter; 00389 00390 // set lvalues 00391 template<typename _Res, typename _Arg> 00392 struct _Setter<_Res, _Arg&> 00393 { 00394 // check this is only used by promise<R>::set_value(const R&) 00395 // or promise<R>::set_value(R&) 00396 static_assert(is_same<_Res, _Arg&>::value // promise<R&> 00397 || is_same<const _Res, _Arg>::value, // promise<R> 00398 "Invalid specialisation"); 00399 00400 typename promise<_Res>::_Ptr_type operator()() 00401 { 00402 _State_base::_S_check(_M_promise->_M_future); 00403 _M_promise->_M_storage->_M_set(_M_arg); 00404 return std::move(_M_promise->_M_storage); 00405 } 00406 promise<_Res>* _M_promise; 00407 _Arg& _M_arg; 00408 }; 00409 00410 // set rvalues 00411 template<typename _Res> 00412 struct _Setter<_Res, _Res&&> 00413 { 00414 typename promise<_Res>::_Ptr_type operator()() 00415 { 00416 _State_base::_S_check(_M_promise->_M_future); 00417 _M_promise->_M_storage->_M_set(std::move(_M_arg)); 00418 return std::move(_M_promise->_M_storage); 00419 } 00420 promise<_Res>* _M_promise; 00421 _Res& _M_arg; 00422 }; 00423 00424 struct __exception_ptr_tag { }; 00425 00426 // set exceptions 00427 template<typename _Res> 00428 struct _Setter<_Res, __exception_ptr_tag> 00429 { 00430 typename promise<_Res>::_Ptr_type operator()() 00431 { 00432 _State_base::_S_check(_M_promise->_M_future); 00433 _M_promise->_M_storage->_M_error = _M_ex; 00434 return std::move(_M_promise->_M_storage); 00435 } 00436 00437 promise<_Res>* _M_promise; 00438 exception_ptr& _M_ex; 00439 }; 00440 00441 template<typename _Res, typename _Arg> 00442 static _Setter<_Res, _Arg&&> 00443 __setter(promise<_Res>* __prom, _Arg&& __arg) 00444 { 00445 return _Setter<_Res, _Arg&&>{ __prom, __arg }; 00446 } 00447 00448 template<typename _Res> 00449 static _Setter<_Res, __exception_ptr_tag> 00450 __setter(exception_ptr& __ex, promise<_Res>* __prom) 00451 { 00452 return _Setter<_Res, __exception_ptr_tag>{ __prom, __ex }; 00453 } 00454 00455 static _Setter<void, void> 00456 __setter(promise<void>* __prom); 00457 00458 template<typename _Tp> 00459 static bool 00460 _S_check(const shared_ptr<_Tp>& __p) 00461 { 00462 if (!static_cast<bool>(__p)) 00463 __throw_future_error((int)future_errc::no_state); 00464 } 00465 00466 private: 00467 void 00468 _M_do_set(function<_Ptr_type()>& __f, bool& __set) 00469 { 00470 _Ptr_type __res = __f(); 00471 { 00472 lock_guard<mutex> __lock(_M_mutex); 00473 _M_result.swap(__res); 00474 } 00475 _M_cond.notify_all(); 00476 __set = true; 00477 } 00478 00479 bool _M_ready() const noexcept { return static_cast<bool>(_M_result); } 00480 00481 // Misnamed: waits for completion of async function. 00482 virtual void _M_run_deferred() { } 00483 }; 00484 00485 template<typename _BoundFn, typename = typename _BoundFn::result_type> 00486 class _Deferred_state; 00487 00488 class _Async_state_common; 00489 00490 template<typename _BoundFn, typename = typename _BoundFn::result_type> 00491 class _Async_state_impl; 00492 00493 template<typename _Signature> 00494 class _Task_state; 00495 00496 template<typename _BoundFn> 00497 static std::shared_ptr<_State_base> 00498 _S_make_deferred_state(_BoundFn&& __fn); 00499 00500 template<typename _BoundFn> 00501 static std::shared_ptr<_State_base> 00502 _S_make_async_state(_BoundFn&& __fn); 00503 00504 template<typename _Res_ptr, typename _Res> 00505 struct _Task_setter; 00506 00507 template<typename _Res_ptr, typename _BoundFn> 00508 class _Task_setter_helper 00509 { 00510 typedef typename remove_reference<_BoundFn>::type::result_type __res; 00511 public: 00512 typedef _Task_setter<_Res_ptr, __res> __type; 00513 }; 00514 00515 template<typename _Res_ptr, typename _BoundFn> 00516 static typename _Task_setter_helper<_Res_ptr, _BoundFn>::__type 00517 _S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call) 00518 { 00519 typedef _Task_setter_helper<_Res_ptr, _BoundFn> __helper_type; 00520 typedef typename __helper_type::__type _Setter; 00521 return _Setter{ __ptr, std::ref(__call) }; 00522 } 00523 }; 00524 00525 /// Partial specialization for reference types. 00526 template<typename _Res> 00527 struct __future_base::_Result<_Res&> : __future_base::_Result_base 00528 { 00529 _Result() noexcept : _M_value_ptr() { } 00530 00531 void _M_set(_Res& __res) noexcept { _M_value_ptr = &__res; } 00532 00533 _Res& _M_get() noexcept { return *_M_value_ptr; } 00534 00535 private: 00536 _Res* _M_value_ptr; 00537 00538 void _M_destroy() { delete this; } 00539 }; 00540 00541 /// Explicit specialization for void. 00542 template<> 00543 struct __future_base::_Result<void> : __future_base::_Result_base 00544 { 00545 private: 00546 void _M_destroy() { delete this; } 00547 }; 00548 00549 00550 /// Common implementation for future and shared_future. 00551 template<typename _Res> 00552 class __basic_future : public __future_base 00553 { 00554 protected: 00555 typedef shared_ptr<_State_base> __state_type; 00556 typedef __future_base::_Result<_Res>& __result_type; 00557 00558 private: 00559 __state_type _M_state; 00560 00561 public: 00562 // Disable copying. 00563 __basic_future(const __basic_future&) = delete; 00564 __basic_future& operator=(const __basic_future&) = delete; 00565 00566 bool 00567 valid() const noexcept { return static_cast<bool>(_M_state); } 00568 00569 void 00570 wait() const 00571 { 00572 _State_base::_S_check(_M_state); 00573 _M_state->wait(); 00574 } 00575 00576 template<typename _Rep, typename _Period> 00577 future_status 00578 wait_for(const chrono::duration<_Rep, _Period>& __rel) const 00579 { 00580 _State_base::_S_check(_M_state); 00581 return _M_state->wait_for(__rel); 00582 } 00583 00584 template<typename _Clock, typename _Duration> 00585 future_status 00586 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const 00587 { 00588 _State_base::_S_check(_M_state); 00589 return _M_state->wait_until(__abs); 00590 } 00591 00592 protected: 00593 /// Wait for the state to be ready and rethrow any stored exception 00594 __result_type 00595 _M_get_result() 00596 { 00597 _State_base::_S_check(_M_state); 00598 _Result_base& __res = _M_state->wait(); 00599 if (!(__res._M_error == 0)) 00600 rethrow_exception(__res._M_error); 00601 return static_cast<__result_type>(__res); 00602 } 00603 00604 void _M_swap(__basic_future& __that) noexcept 00605 { 00606 _M_state.swap(__that._M_state); 00607 } 00608 00609 // Construction of a future by promise::get_future() 00610 explicit 00611 __basic_future(const __state_type& __state) : _M_state(__state) 00612 { 00613 _State_base::_S_check(_M_state); 00614 _M_state->_M_set_retrieved_flag(); 00615 } 00616 00617 // Copy construction from a shared_future 00618 explicit 00619 __basic_future(const shared_future<_Res>&) noexcept; 00620 00621 // Move construction from a shared_future 00622 explicit 00623 __basic_future(shared_future<_Res>&&) noexcept; 00624 00625 // Move construction from a future 00626 explicit 00627 __basic_future(future<_Res>&&) noexcept; 00628 00629 constexpr __basic_future() noexcept : _M_state() { } 00630 00631 struct _Reset 00632 { 00633 explicit _Reset(__basic_future& __fut) noexcept : _M_fut(__fut) { } 00634 ~_Reset() { _M_fut._M_state.reset(); } 00635 __basic_future& _M_fut; 00636 }; 00637 }; 00638 00639 00640 /// Primary template for future. 00641 template<typename _Res> 00642 class future : public __basic_future<_Res> 00643 { 00644 friend class promise<_Res>; 00645 template<typename> friend class packaged_task; 00646 template<typename _Fn, typename... _Args> 00647 friend future<typename result_of<_Fn(_Args...)>::type> 00648 async(launch, _Fn&&, _Args&&...); 00649 00650 typedef __basic_future<_Res> _Base_type; 00651 typedef typename _Base_type::__state_type __state_type; 00652 00653 explicit 00654 future(const __state_type& __state) : _Base_type(__state) { } 00655 00656 public: 00657 constexpr future() noexcept : _Base_type() { } 00658 00659 /// Move constructor 00660 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00661 00662 // Disable copying 00663 future(const future&) = delete; 00664 future& operator=(const future&) = delete; 00665 00666 future& operator=(future&& __fut) noexcept 00667 { 00668 future(std::move(__fut))._M_swap(*this); 00669 return *this; 00670 } 00671 00672 /// Retrieving the value 00673 _Res 00674 get() 00675 { 00676 typename _Base_type::_Reset __reset(*this); 00677 return std::move(this->_M_get_result()._M_value()); 00678 } 00679 00680 shared_future<_Res> share(); 00681 }; 00682 00683 /// Partial specialization for future<R&> 00684 template<typename _Res> 00685 class future<_Res&> : public __basic_future<_Res&> 00686 { 00687 friend class promise<_Res&>; 00688 template<typename> friend class packaged_task; 00689 template<typename _Fn, typename... _Args> 00690 friend future<typename result_of<_Fn(_Args...)>::type> 00691 async(launch, _Fn&&, _Args&&...); 00692 00693 typedef __basic_future<_Res&> _Base_type; 00694 typedef typename _Base_type::__state_type __state_type; 00695 00696 explicit 00697 future(const __state_type& __state) : _Base_type(__state) { } 00698 00699 public: 00700 constexpr future() noexcept : _Base_type() { } 00701 00702 /// Move constructor 00703 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00704 00705 // Disable copying 00706 future(const future&) = delete; 00707 future& operator=(const future&) = delete; 00708 00709 future& operator=(future&& __fut) noexcept 00710 { 00711 future(std::move(__fut))._M_swap(*this); 00712 return *this; 00713 } 00714 00715 /// Retrieving the value 00716 _Res& 00717 get() 00718 { 00719 typename _Base_type::_Reset __reset(*this); 00720 return this->_M_get_result()._M_get(); 00721 } 00722 00723 shared_future<_Res&> share(); 00724 }; 00725 00726 /// Explicit specialization for future<void> 00727 template<> 00728 class future<void> : public __basic_future<void> 00729 { 00730 friend class promise<void>; 00731 template<typename> friend class packaged_task; 00732 template<typename _Fn, typename... _Args> 00733 friend future<typename result_of<_Fn(_Args...)>::type> 00734 async(launch, _Fn&&, _Args&&...); 00735 00736 typedef __basic_future<void> _Base_type; 00737 typedef typename _Base_type::__state_type __state_type; 00738 00739 explicit 00740 future(const __state_type& __state) : _Base_type(__state) { } 00741 00742 public: 00743 constexpr future() noexcept : _Base_type() { } 00744 00745 /// Move constructor 00746 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00747 00748 // Disable copying 00749 future(const future&) = delete; 00750 future& operator=(const future&) = delete; 00751 00752 future& operator=(future&& __fut) noexcept 00753 { 00754 future(std::move(__fut))._M_swap(*this); 00755 return *this; 00756 } 00757 00758 /// Retrieving the value 00759 void 00760 get() 00761 { 00762 typename _Base_type::_Reset __reset(*this); 00763 this->_M_get_result(); 00764 } 00765 00766 shared_future<void> share(); 00767 }; 00768 00769 00770 /// Primary template for shared_future. 00771 template<typename _Res> 00772 class shared_future : public __basic_future<_Res> 00773 { 00774 typedef __basic_future<_Res> _Base_type; 00775 00776 public: 00777 constexpr shared_future() noexcept : _Base_type() { } 00778 00779 /// Copy constructor 00780 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00781 00782 /// Construct from a future rvalue 00783 shared_future(future<_Res>&& __uf) noexcept 00784 : _Base_type(std::move(__uf)) 00785 { } 00786 00787 /// Construct from a shared_future rvalue 00788 shared_future(shared_future&& __sf) noexcept 00789 : _Base_type(std::move(__sf)) 00790 { } 00791 00792 shared_future& operator=(const shared_future& __sf) 00793 { 00794 shared_future(__sf)._M_swap(*this); 00795 return *this; 00796 } 00797 00798 shared_future& operator=(shared_future&& __sf) noexcept 00799 { 00800 shared_future(std::move(__sf))._M_swap(*this); 00801 return *this; 00802 } 00803 00804 /// Retrieving the value 00805 const _Res& 00806 get() 00807 { 00808 typename _Base_type::__result_type __r = this->_M_get_result(); 00809 _Res& __rs(__r._M_value()); 00810 return __rs; 00811 } 00812 }; 00813 00814 /// Partial specialization for shared_future<R&> 00815 template<typename _Res> 00816 class shared_future<_Res&> : public __basic_future<_Res&> 00817 { 00818 typedef __basic_future<_Res&> _Base_type; 00819 00820 public: 00821 constexpr shared_future() noexcept : _Base_type() { } 00822 00823 /// Copy constructor 00824 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00825 00826 /// Construct from a future rvalue 00827 shared_future(future<_Res&>&& __uf) noexcept 00828 : _Base_type(std::move(__uf)) 00829 { } 00830 00831 /// Construct from a shared_future rvalue 00832 shared_future(shared_future&& __sf) noexcept 00833 : _Base_type(std::move(__sf)) 00834 { } 00835 00836 shared_future& operator=(const shared_future& __sf) 00837 { 00838 shared_future(__sf)._M_swap(*this); 00839 return *this; 00840 } 00841 00842 shared_future& operator=(shared_future&& __sf) noexcept 00843 { 00844 shared_future(std::move(__sf))._M_swap(*this); 00845 return *this; 00846 } 00847 00848 /// Retrieving the value 00849 _Res& 00850 get() { return this->_M_get_result()._M_get(); } 00851 }; 00852 00853 /// Explicit specialization for shared_future<void> 00854 template<> 00855 class shared_future<void> : public __basic_future<void> 00856 { 00857 typedef __basic_future<void> _Base_type; 00858 00859 public: 00860 constexpr shared_future() noexcept : _Base_type() { } 00861 00862 /// Copy constructor 00863 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00864 00865 /// Construct from a future rvalue 00866 shared_future(future<void>&& __uf) noexcept 00867 : _Base_type(std::move(__uf)) 00868 { } 00869 00870 /// Construct from a shared_future rvalue 00871 shared_future(shared_future&& __sf) noexcept 00872 : _Base_type(std::move(__sf)) 00873 { } 00874 00875 shared_future& operator=(const shared_future& __sf) 00876 { 00877 shared_future(__sf)._M_swap(*this); 00878 return *this; 00879 } 00880 00881 shared_future& operator=(shared_future&& __sf) noexcept 00882 { 00883 shared_future(std::move(__sf))._M_swap(*this); 00884 return *this; 00885 } 00886 00887 // Retrieving the value 00888 void 00889 get() { this->_M_get_result(); } 00890 }; 00891 00892 // Now we can define the protected __basic_future constructors. 00893 template<typename _Res> 00894 inline __basic_future<_Res>:: 00895 __basic_future(const shared_future<_Res>& __sf) noexcept 00896 : _M_state(__sf._M_state) 00897 { } 00898 00899 template<typename _Res> 00900 inline __basic_future<_Res>:: 00901 __basic_future(shared_future<_Res>&& __sf) noexcept 00902 : _M_state(std::move(__sf._M_state)) 00903 { } 00904 00905 template<typename _Res> 00906 inline __basic_future<_Res>:: 00907 __basic_future(future<_Res>&& __uf) noexcept 00908 : _M_state(std::move(__uf._M_state)) 00909 { } 00910 00911 template<typename _Res> 00912 inline shared_future<_Res> 00913 future<_Res>::share() 00914 { return shared_future<_Res>(std::move(*this)); } 00915 00916 template<typename _Res> 00917 inline shared_future<_Res&> 00918 future<_Res&>::share() 00919 { return shared_future<_Res&>(std::move(*this)); } 00920 00921 inline shared_future<void> 00922 future<void>::share() 00923 { return shared_future<void>(std::move(*this)); } 00924 00925 /// Primary template for promise 00926 template<typename _Res> 00927 class promise 00928 { 00929 typedef __future_base::_State_base _State; 00930 typedef __future_base::_Result<_Res> _Res_type; 00931 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 00932 template<typename, typename> friend class _State::_Setter; 00933 00934 shared_ptr<_State> _M_future; 00935 _Ptr_type _M_storage; 00936 00937 public: 00938 promise() 00939 : _M_future(std::make_shared<_State>()), 00940 _M_storage(new _Res_type()) 00941 { } 00942 00943 promise(promise&& __rhs) noexcept 00944 : _M_future(std::move(__rhs._M_future)), 00945 _M_storage(std::move(__rhs._M_storage)) 00946 { } 00947 00948 template<typename _Allocator> 00949 promise(allocator_arg_t, const _Allocator& __a) 00950 : _M_future(std::allocate_shared<_State>(__a)), 00951 _M_storage(__future_base::_S_allocate_result<_Res>(__a)) 00952 { } 00953 00954 template<typename _Allocator> 00955 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 00956 : _M_future(std::move(__rhs._M_future)), 00957 _M_storage(std::move(__rhs._M_storage)) 00958 { } 00959 00960 promise(const promise&) = delete; 00961 00962 ~promise() 00963 { 00964 if (static_cast<bool>(_M_future) && !_M_future.unique()) 00965 _M_future->_M_break_promise(std::move(_M_storage)); 00966 } 00967 00968 // Assignment 00969 promise& 00970 operator=(promise&& __rhs) noexcept 00971 { 00972 promise(std::move(__rhs)).swap(*this); 00973 return *this; 00974 } 00975 00976 promise& operator=(const promise&) = delete; 00977 00978 void 00979 swap(promise& __rhs) noexcept 00980 { 00981 _M_future.swap(__rhs._M_future); 00982 _M_storage.swap(__rhs._M_storage); 00983 } 00984 00985 // Retrieving the result 00986 future<_Res> 00987 get_future() 00988 { return future<_Res>(_M_future); } 00989 00990 // Setting the result 00991 void 00992 set_value(const _Res& __r) 00993 { 00994 auto __setter = _State::__setter(this, __r); 00995 _M_future->_M_set_result(std::move(__setter)); 00996 } 00997 00998 void 00999 set_value(_Res&& __r) 01000 { 01001 auto __setter = _State::__setter(this, std::move(__r)); 01002 _M_future->_M_set_result(std::move(__setter)); 01003 } 01004 01005 void 01006 set_exception(exception_ptr __p) 01007 { 01008 auto __setter = _State::__setter(__p, this); 01009 _M_future->_M_set_result(std::move(__setter)); 01010 } 01011 }; 01012 01013 template<typename _Res> 01014 inline void 01015 swap(promise<_Res>& __x, promise<_Res>& __y) noexcept 01016 { __x.swap(__y); } 01017 01018 template<typename _Res, typename _Alloc> 01019 struct uses_allocator<promise<_Res>, _Alloc> 01020 : public true_type { }; 01021 01022 01023 /// Partial specialization for promise<R&> 01024 template<typename _Res> 01025 class promise<_Res&> 01026 { 01027 typedef __future_base::_State_base _State; 01028 typedef __future_base::_Result<_Res&> _Res_type; 01029 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 01030 template<typename, typename> friend class _State::_Setter; 01031 01032 shared_ptr<_State> _M_future; 01033 _Ptr_type _M_storage; 01034 01035 public: 01036 promise() 01037 : _M_future(std::make_shared<_State>()), 01038 _M_storage(new _Res_type()) 01039 { } 01040 01041 promise(promise&& __rhs) noexcept 01042 : _M_future(std::move(__rhs._M_future)), 01043 _M_storage(std::move(__rhs._M_storage)) 01044 { } 01045 01046 template<typename _Allocator> 01047 promise(allocator_arg_t, const _Allocator& __a) 01048 : _M_future(std::allocate_shared<_State>(__a)), 01049 _M_storage(__future_base::_S_allocate_result<_Res&>(__a)) 01050 { } 01051 01052 template<typename _Allocator> 01053 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 01054 : _M_future(std::move(__rhs._M_future)), 01055 _M_storage(std::move(__rhs._M_storage)) 01056 { } 01057 01058 promise(const promise&) = delete; 01059 01060 ~promise() 01061 { 01062 if (static_cast<bool>(_M_future) && !_M_future.unique()) 01063 _M_future->_M_break_promise(std::move(_M_storage)); 01064 } 01065 01066 // Assignment 01067 promise& 01068 operator=(promise&& __rhs) noexcept 01069 { 01070 promise(std::move(__rhs)).swap(*this); 01071 return *this; 01072 } 01073 01074 promise& operator=(const promise&) = delete; 01075 01076 void 01077 swap(promise& __rhs) noexcept 01078 { 01079 _M_future.swap(__rhs._M_future); 01080 _M_storage.swap(__rhs._M_storage); 01081 } 01082 01083 // Retrieving the result 01084 future<_Res&> 01085 get_future() 01086 { return future<_Res&>(_M_future); } 01087 01088 // Setting the result 01089 void 01090 set_value(_Res& __r) 01091 { 01092 auto __setter = _State::__setter(this, __r); 01093 _M_future->_M_set_result(std::move(__setter)); 01094 } 01095 01096 void 01097 set_exception(exception_ptr __p) 01098 { 01099 auto __setter = _State::__setter(__p, this); 01100 _M_future->_M_set_result(std::move(__setter)); 01101 } 01102 }; 01103 01104 /// Explicit specialization for promise<void> 01105 template<> 01106 class promise<void> 01107 { 01108 typedef __future_base::_State_base _State; 01109 typedef __future_base::_Result<void> _Res_type; 01110 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 01111 template<typename, typename> friend class _State::_Setter; 01112 01113 shared_ptr<_State> _M_future; 01114 _Ptr_type _M_storage; 01115 01116 public: 01117 promise() 01118 : _M_future(std::make_shared<_State>()), 01119 _M_storage(new _Res_type()) 01120 { } 01121 01122 promise(promise&& __rhs) noexcept 01123 : _M_future(std::move(__rhs._M_future)), 01124 _M_storage(std::move(__rhs._M_storage)) 01125 { } 01126 01127 template<typename _Allocator> 01128 promise(allocator_arg_t, const _Allocator& __a) 01129 : _M_future(std::allocate_shared<_State>(__a)), 01130 _M_storage(__future_base::_S_allocate_result<void>(__a)) 01131 { } 01132 01133 template<typename _Allocator> 01134 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 01135 : _M_future(std::move(__rhs._M_future)), 01136 _M_storage(std::move(__rhs._M_storage)) 01137 { } 01138 01139 promise(const promise&) = delete; 01140 01141 ~promise() 01142 { 01143 if (static_cast<bool>(_M_future) && !_M_future.unique()) 01144 _M_future->_M_break_promise(std::move(_M_storage)); 01145 } 01146 01147 // Assignment 01148 promise& 01149 operator=(promise&& __rhs) noexcept 01150 { 01151 promise(std::move(__rhs)).swap(*this); 01152 return *this; 01153 } 01154 01155 promise& operator=(const promise&) = delete; 01156 01157 void 01158 swap(promise& __rhs) noexcept 01159 { 01160 _M_future.swap(__rhs._M_future); 01161 _M_storage.swap(__rhs._M_storage); 01162 } 01163 01164 // Retrieving the result 01165 future<void> 01166 get_future() 01167 { return future<void>(_M_future); } 01168 01169 // Setting the result 01170 void set_value(); 01171 01172 void 01173 set_exception(exception_ptr __p) 01174 { 01175 auto __setter = _State::__setter(__p, this); 01176 _M_future->_M_set_result(std::move(__setter)); 01177 } 01178 }; 01179 01180 // set void 01181 template<> 01182 struct __future_base::_State_base::_Setter<void, void> 01183 { 01184 promise<void>::_Ptr_type operator()() 01185 { 01186 _State_base::_S_check(_M_promise->_M_future); 01187 return std::move(_M_promise->_M_storage); 01188 } 01189 01190 promise<void>* _M_promise; 01191 }; 01192 01193 inline __future_base::_State_base::_Setter<void, void> 01194 __future_base::_State_base::__setter(promise<void>* __prom) 01195 { 01196 return _Setter<void, void>{ __prom }; 01197 } 01198 01199 inline void 01200 promise<void>::set_value() 01201 { 01202 auto __setter = _State::__setter(this); 01203 _M_future->_M_set_result(std::move(__setter)); 01204 } 01205 01206 01207 template<typename _Ptr_type, typename _Res> 01208 struct __future_base::_Task_setter 01209 { 01210 _Ptr_type operator()() 01211 { 01212 __try 01213 { 01214 _M_result->_M_set(_M_fn()); 01215 } 01216 __catch(...) 01217 { 01218 _M_result->_M_error = current_exception(); 01219 } 01220 return std::move(_M_result); 01221 } 01222 _Ptr_type& _M_result; 01223 std::function<_Res()> _M_fn; 01224 }; 01225 01226 template<typename _Ptr_type> 01227 struct __future_base::_Task_setter<_Ptr_type, void> 01228 { 01229 _Ptr_type operator()() 01230 { 01231 __try 01232 { 01233 _M_fn(); 01234 } 01235 __catch(...) 01236 { 01237 _M_result->_M_error = current_exception(); 01238 } 01239 return std::move(_M_result); 01240 } 01241 _Ptr_type& _M_result; 01242 std::function<void()> _M_fn; 01243 }; 01244 01245 template<typename _Res, typename... _Args> 01246 struct __future_base::_Task_state<_Res(_Args...)> final 01247 : __future_base::_State_base 01248 { 01249 typedef _Res _Res_type; 01250 01251 _Task_state(std::function<_Res(_Args...)> __task) 01252 : _M_result(new _Result<_Res>()), _M_task(std::move(__task)) 01253 { } 01254 01255 template<typename _Func, typename _Alloc> 01256 _Task_state(_Func&& __task, const _Alloc& __a) 01257 : _M_result(_S_allocate_result<_Res>(__a)), 01258 _M_task(allocator_arg, __a, std::move(__task)) 01259 { } 01260 01261 void 01262 _M_run(_Args... __args) 01263 { 01264 // bound arguments decay so wrap lvalue references 01265 auto __boundfn = std::__bind_simple(std::ref(_M_task), 01266 _S_maybe_wrap_ref(std::forward<_Args>(__args))...); 01267 auto __setter = _S_task_setter(_M_result, std::move(__boundfn)); 01268 _M_set_result(std::move(__setter)); 01269 } 01270 01271 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01272 _Ptr_type _M_result; 01273 std::function<_Res(_Args...)> _M_task; 01274 01275 template<typename _Tp> 01276 static reference_wrapper<_Tp> 01277 _S_maybe_wrap_ref(_Tp& __t) 01278 { return std::ref(__t); } 01279 01280 template<typename _Tp> 01281 static typename enable_if<!is_lvalue_reference<_Tp>::value, 01282 _Tp>::type&& 01283 _S_maybe_wrap_ref(_Tp&& __t) 01284 { return std::forward<_Tp>(__t); } 01285 }; 01286 01287 template<typename _Task, typename _Fn, bool 01288 = is_same<_Task, typename decay<_Fn>::type>::value> 01289 struct __constrain_pkgdtask 01290 { typedef void __type; }; 01291 01292 template<typename _Task, typename _Fn> 01293 struct __constrain_pkgdtask<_Task, _Fn, true> 01294 { }; 01295 01296 /// packaged_task 01297 template<typename _Res, typename... _ArgTypes> 01298 class packaged_task<_Res(_ArgTypes...)> 01299 { 01300 typedef __future_base::_Task_state<_Res(_ArgTypes...)> _State_type; 01301 shared_ptr<_State_type> _M_state; 01302 01303 public: 01304 // Construction and destruction 01305 packaged_task() noexcept { } 01306 01307 template<typename _Allocator> 01308 explicit 01309 packaged_task(allocator_arg_t, const _Allocator& __a) noexcept 01310 { } 01311 01312 template<typename _Fn, typename = typename 01313 __constrain_pkgdtask<packaged_task, _Fn>::__type> 01314 explicit 01315 packaged_task(_Fn&& __fn) 01316 : _M_state(std::make_shared<_State_type>(std::forward<_Fn>(__fn))) 01317 { } 01318 01319 template<typename _Fn, typename _Allocator, typename = typename 01320 __constrain_pkgdtask<packaged_task, _Fn>::__type> 01321 explicit 01322 packaged_task(allocator_arg_t, const _Allocator& __a, _Fn&& __fn) 01323 : _M_state(std::allocate_shared<_State_type>(__a, 01324 std::forward<_Fn>(__fn))) 01325 { } 01326 01327 ~packaged_task() 01328 { 01329 if (static_cast<bool>(_M_state) && !_M_state.unique()) 01330 _M_state->_M_break_promise(std::move(_M_state->_M_result)); 01331 } 01332 01333 // No copy 01334 packaged_task(const packaged_task&) = delete; 01335 packaged_task& operator=(const packaged_task&) = delete; 01336 01337 template<typename _Allocator> 01338 explicit 01339 packaged_task(allocator_arg_t, const _Allocator&, 01340 const packaged_task&) = delete; 01341 01342 // Move support 01343 packaged_task(packaged_task&& __other) noexcept 01344 { this->swap(__other); } 01345 01346 template<typename _Allocator> 01347 explicit 01348 packaged_task(allocator_arg_t, const _Allocator&, 01349 packaged_task&& __other) noexcept 01350 { this->swap(__other); } 01351 01352 packaged_task& operator=(packaged_task&& __other) noexcept 01353 { 01354 packaged_task(std::move(__other)).swap(*this); 01355 return *this; 01356 } 01357 01358 void 01359 swap(packaged_task& __other) noexcept 01360 { _M_state.swap(__other._M_state); } 01361 01362 bool 01363 valid() const noexcept 01364 { return static_cast<bool>(_M_state); } 01365 01366 // Result retrieval 01367 future<_Res> 01368 get_future() 01369 { return future<_Res>(_M_state); } 01370 01371 // Execution 01372 void 01373 operator()(_ArgTypes... __args) 01374 { 01375 __future_base::_State_base::_S_check(_M_state); 01376 _M_state->_M_run(std::forward<_ArgTypes>(__args)...); 01377 } 01378 01379 void 01380 reset() 01381 { 01382 __future_base::_State_base::_S_check(_M_state); 01383 packaged_task(std::move(_M_state->_M_task)).swap(*this); 01384 } 01385 }; 01386 01387 /// swap 01388 template<typename _Res, typename... _ArgTypes> 01389 inline void 01390 swap(packaged_task<_Res(_ArgTypes...)>& __x, 01391 packaged_task<_Res(_ArgTypes...)>& __y) noexcept 01392 { __x.swap(__y); } 01393 01394 template<typename _Res, typename _Alloc> 01395 struct uses_allocator<packaged_task<_Res>, _Alloc> 01396 : public true_type { }; 01397 01398 01399 template<typename _BoundFn, typename _Res> 01400 class __future_base::_Deferred_state final 01401 : public __future_base::_State_base 01402 { 01403 public: 01404 explicit 01405 _Deferred_state(_BoundFn&& __fn) 01406 : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)) 01407 { } 01408 01409 private: 01410 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01411 _Ptr_type _M_result; 01412 _BoundFn _M_fn; 01413 01414 virtual void 01415 _M_run_deferred() 01416 { 01417 // safe to call multiple times so ignore failure 01418 _M_set_result(_S_task_setter(_M_result, _M_fn), true); 01419 } 01420 }; 01421 01422 class __future_base::_Async_state_common : public __future_base::_State_base 01423 { 01424 protected: 01425 #ifdef _GLIBCXX_ASYNC_ABI_COMPAT 01426 ~_Async_state_common(); 01427 #else 01428 ~_Async_state_common() = default; 01429 #endif 01430 01431 // Allow non-timed waiting functions to block until the thread completes, 01432 // as if joined. 01433 virtual void _M_run_deferred() { _M_join(); } 01434 01435 void _M_join() { std::call_once(_M_once, &thread::join, ref(_M_thread)); } 01436 01437 thread _M_thread; 01438 once_flag _M_once; 01439 }; 01440 01441 template<typename _BoundFn, typename _Res> 01442 class __future_base::_Async_state_impl final 01443 : public __future_base::_Async_state_common 01444 { 01445 public: 01446 explicit 01447 _Async_state_impl(_BoundFn&& __fn) 01448 : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)) 01449 { 01450 _M_thread = std::thread{ [this] { 01451 _M_set_result(_S_task_setter(_M_result, _M_fn)); 01452 } }; 01453 } 01454 01455 ~_Async_state_impl() { _M_join(); } 01456 01457 private: 01458 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01459 _Ptr_type _M_result; 01460 _BoundFn _M_fn; 01461 }; 01462 01463 template<typename _BoundFn> 01464 inline std::shared_ptr<__future_base::_State_base> 01465 __future_base::_S_make_deferred_state(_BoundFn&& __fn) 01466 { 01467 typedef typename remove_reference<_BoundFn>::type __fn_type; 01468 typedef _Deferred_state<__fn_type> __state_type; 01469 return std::make_shared<__state_type>(std::move(__fn)); 01470 } 01471 01472 template<typename _BoundFn> 01473 inline std::shared_ptr<__future_base::_State_base> 01474 __future_base::_S_make_async_state(_BoundFn&& __fn) 01475 { 01476 typedef typename remove_reference<_BoundFn>::type __fn_type; 01477 typedef _Async_state_impl<__fn_type> __state_type; 01478 return std::make_shared<__state_type>(std::move(__fn)); 01479 } 01480 01481 01482 /// async 01483 template<typename _Fn, typename... _Args> 01484 future<typename result_of<_Fn(_Args...)>::type> 01485 async(launch __policy, _Fn&& __fn, _Args&&... __args) 01486 { 01487 typedef typename result_of<_Fn(_Args...)>::type result_type; 01488 std::shared_ptr<__future_base::_State_base> __state; 01489 if ((__policy & (launch::async|launch::deferred)) == launch::async) 01490 { 01491 __state = __future_base::_S_make_async_state(std::__bind_simple( 01492 std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); 01493 } 01494 else 01495 { 01496 __state = __future_base::_S_make_deferred_state(std::__bind_simple( 01497 std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); 01498 } 01499 return future<result_type>(__state); 01500 } 01501 01502 /// async, potential overload 01503 template<typename _Fn, typename... _Args> 01504 inline typename 01505 __async_sfinae_helper<typename decay<_Fn>::type, _Fn, _Args...>::type 01506 async(_Fn&& __fn, _Args&&... __args) 01507 { 01508 return async(launch::async|launch::deferred, std::forward<_Fn>(__fn), 01509 std::forward<_Args>(__args)...); 01510 } 01511 01512 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 01513 // && ATOMIC_INT_LOCK_FREE 01514 01515 // @} group futures 01516 _GLIBCXX_END_NAMESPACE_VERSION 01517 } // namespace 01518 01519 #endif // __GXX_EXPERIMENTAL_CXX0X__ 01520 01521 #endif // _GLIBCXX_FUTURE