OSDN Git Service

2010-01-21 Jonathan Wakely <jwakely.gcc@gmail.com>
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Jan 2010 00:01:47 +0000 (00:01 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Jan 2010 00:01:47 +0000 (00:01 +0000)
        PR libstdc++/42201
* include/std/future: Update to latest WP.
* src/functexcept.cc (__throw_future_error): Use make_error_code.
* testsuite/30_threads/async/any.cc: New.
* testsuite/30_threads/async/async.cc: New.
* testsuite/30_threads/async/sync.cc: New.
* testsuite/30_threads/packaged_task/cons/alloc.cc: New.
* testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust.
* testsuite/30_threads/packaged_task/cons/copy_neg.cc: Adjust.
* testsuite/30_threads/packaged_task/members/get_future.cc: Adjust.
* testsuite/30_threads/packaged_task/members/get_future2.cc: Likewise.
* testsuite/30_threads/packaged_task/members/invoke.cc: Adjust.
* testsuite/30_threads/packaged_task/members/invoke2.cc: Adjust.
* testsuite/30_threads/packaged_task/members/invoke3.cc: Adjust.
* testsuite/30_threads/packaged_task/members/invoke4.cc: Adjust.
* testsuite/30_threads/packaged_task/members/reset.cc: Adjust.
* testsuite/30_threads/packaged_task/members/reset2.cc: Adjust.
* testsuite/30_threads/shared_future/cons/assign_neg.cc: Remove.
* testsuite/30_threads/shared_future/cons/default_neg.cc: Remove.
* testsuite/30_threads/shared_future/cons/default.cc: New.
* testsuite/30_threads/shared_future/cons/assign.cc: New.
* testsuite/30_threads/shared_future/cons/copy.cc: Adjust.
* testsuite/30_threads/shared_future/cons/move.cc: Adjust.
* testsuite/30_threads/shared_future/cons/move_assign.cc: New.
* testsuite/30_threads/shared_future/members/is_ready.cc: Remove.
* testsuite/30_threads/shared_future/members/has_value.cc: Remove.
* testsuite/30_threads/shared_future/members/has_exception.cc: Remove.
* testsuite/30_threads/shared_future/members/valid.cc: New.
* testsuite/30_threads/unique_future/cons/default_neg.cc: Remove.
* testsuite/30_threads/unique_future/cons/default.cc: New.
* testsuite/30_threads/unique_future/cons/move_assign.cc: New.
* testsuite/30_threads/unique_future/cons/assign_neg.cc: Adjust.
* testsuite/30_threads/unique_future/cons/copy_neg.cc: Adjust.
* testsuite/30_threads/unique_future/cons/move.cc: Adjust.
* testsuite/30_threads/unique_future/requirements/
        explicit_instantiation.cc: Adjust.
* testsuite/30_threads/unique_future/members/is_ready.cc: Remove.
* testsuite/30_threads/unique_future/members/has_value.cc: Remove.
* testsuite/30_threads/unique_future/members/has_exception.cc: Remove.
* testsuite/30_threads/unique_future/members/valid.cc: New.
* testsuite/30_threads/unique_future/members/get.cc: Adjust.
* testsuite/30_threads/unique_future/members/get2.cc: Adjust.
* testsuite/30_threads/unique_future/members/wait.cc: Adjust.
* testsuite/30_threads/unique_future/members/wait_for.cc: Adjust.
* testsuite/30_threads/unique_future/members/wait_until.cc: Adjust.
* testsuite/30_threads/headers/future/types_std_c++0x.cc: Adjust.
* testsuite/30_threads/promise/cons/alloc.cc: New.
* testsuite/30_threads/promise/cons/assign_neg.cc: Adjust.
* testsuite/30_threads/promise/cons/copy_neg.cc: Adjust.
* testsuite/30_threads/promise/cons/move.cc: Adjust.
* testsuite/30_threads/promise/cons/move_assign.cc: Adjust.
* testsuite/30_threads/promise/members/get_future.cc: Adjust.
* testsuite/30_threads/promise/members/set_value.cc: Adjust.
* testsuite/30_threads/promise/members/set_exception.cc: Adjust.
* testsuite/30_threads/promise/members/set_exception2.cc: Adjust.
* testsuite/30_threads/promise/members/set_value2.cc: Adjust.
* testsuite/30_threads/promise/members/set_value3.cc: Adjust.
* testsuite/30_threads/promise/members/swap.cc: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156097 138bc75d-0d04-0410-961f-82ee72b054a4

50 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/future
libstdc++-v3/src/functexcept.cc
libstdc++-v3/testsuite/30_threads/async/any.cc [moved from libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc with 74% similarity]
libstdc++-v3/testsuite/30_threads/async/async.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/async/sync.cc [moved from libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc with 79% similarity]
libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc
libstdc++-v3/testsuite/30_threads/packaged_task/cons/alloc.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc
libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc
libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc
libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc
libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc
libstdc++-v3/testsuite/30_threads/promise/cons/move.cc
libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc
libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc
libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc
libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc
libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc
libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc
libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc
libstdc++-v3/testsuite/30_threads/promise/members/swap.cc
libstdc++-v3/testsuite/30_threads/shared_future/cons/assign.cc [moved from libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc with 74% similarity]
libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc
libstdc++-v3/testsuite/30_threads/shared_future/cons/default.cc [moved from libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc with 67% similarity]
libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc
libstdc++-v3/testsuite/30_threads/shared_future/cons/move_assign.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc [deleted file]
libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc [deleted file]
libstdc++-v3/testsuite/30_threads/shared_future/members/valid.cc [moved from libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc with 77% similarity]
libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc
libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc
libstdc++-v3/testsuite/30_threads/unique_future/cons/default.cc [moved from libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc with 65% similarity]
libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc
libstdc++-v3/testsuite/30_threads/unique_future/cons/move_assign.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc
libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc
libstdc++-v3/testsuite/30_threads/unique_future/members/valid.cc [moved from libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc with 84% similarity]
libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc
libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc
libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc
libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc

index d7661bb..c0558f8 100644 (file)
@@ -1,3 +1,64 @@
+2010-01-21  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+        PR libstdc++/42201
+       * include/std/future: Update to latest WP.
+       * src/functexcept.cc (__throw_future_error): Use make_error_code.
+       * testsuite/30_threads/async/any.cc: New.
+       * testsuite/30_threads/async/async.cc: New.
+       * testsuite/30_threads/async/sync.cc: New.
+       * testsuite/30_threads/packaged_task/cons/alloc.cc: New.
+       * testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust.
+       * testsuite/30_threads/packaged_task/cons/copy_neg.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/get_future.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/get_future2.cc: Likewise.
+       * testsuite/30_threads/packaged_task/members/invoke.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/invoke2.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/invoke3.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/invoke4.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/reset.cc: Adjust.
+       * testsuite/30_threads/packaged_task/members/reset2.cc: Adjust.
+       * testsuite/30_threads/shared_future/cons/assign_neg.cc: Remove.
+       * testsuite/30_threads/shared_future/cons/default_neg.cc: Remove.
+       * testsuite/30_threads/shared_future/cons/default.cc: New.
+       * testsuite/30_threads/shared_future/cons/assign.cc: New.
+       * testsuite/30_threads/shared_future/cons/copy.cc: Adjust.
+       * testsuite/30_threads/shared_future/cons/move.cc: Adjust.
+       * testsuite/30_threads/shared_future/cons/move_assign.cc: New.
+       * testsuite/30_threads/shared_future/members/is_ready.cc: Remove.
+       * testsuite/30_threads/shared_future/members/has_value.cc: Remove.
+       * testsuite/30_threads/shared_future/members/has_exception.cc: Remove.
+       * testsuite/30_threads/shared_future/members/valid.cc: New.
+       * testsuite/30_threads/unique_future/cons/default_neg.cc: Remove.
+       * testsuite/30_threads/unique_future/cons/default.cc: New.
+       * testsuite/30_threads/unique_future/cons/move_assign.cc: New.
+       * testsuite/30_threads/unique_future/cons/assign_neg.cc: Adjust.
+       * testsuite/30_threads/unique_future/cons/copy_neg.cc: Adjust.
+       * testsuite/30_threads/unique_future/cons/move.cc: Adjust.
+       * testsuite/30_threads/unique_future/requirements/
+        explicit_instantiation.cc: Adjust.
+       * testsuite/30_threads/unique_future/members/is_ready.cc: Remove.
+       * testsuite/30_threads/unique_future/members/has_value.cc: Remove.
+       * testsuite/30_threads/unique_future/members/has_exception.cc: Remove.
+       * testsuite/30_threads/unique_future/members/valid.cc: New.
+       * testsuite/30_threads/unique_future/members/get.cc: Adjust.
+       * testsuite/30_threads/unique_future/members/get2.cc: Adjust.
+       * testsuite/30_threads/unique_future/members/wait.cc: Adjust.
+       * testsuite/30_threads/unique_future/members/wait_for.cc: Adjust.
+       * testsuite/30_threads/unique_future/members/wait_until.cc: Adjust.
+       * testsuite/30_threads/headers/future/types_std_c++0x.cc: Adjust.
+       * testsuite/30_threads/promise/cons/alloc.cc: New.
+       * testsuite/30_threads/promise/cons/assign_neg.cc: Adjust.
+       * testsuite/30_threads/promise/cons/copy_neg.cc: Adjust.
+       * testsuite/30_threads/promise/cons/move.cc: Adjust.
+       * testsuite/30_threads/promise/cons/move_assign.cc: Adjust.
+       * testsuite/30_threads/promise/members/get_future.cc: Adjust.
+       * testsuite/30_threads/promise/members/set_value.cc: Adjust.
+       * testsuite/30_threads/promise/members/set_exception.cc: Adjust.
+       * testsuite/30_threads/promise/members/set_exception2.cc: Adjust.
+       * testsuite/30_threads/promise/members/set_value2.cc: Adjust.
+       * testsuite/30_threads/promise/members/set_value3.cc: Adjust.
+       * testsuite/30_threads/promise/members/swap.cc: Adjust.
+
 2010-01-20  Janis Johnson  <janis187@us.ibm.com>
            Paolo Carlini  <paolo.carlini@oracle.com>
 
index 44f2ec8..629d61a 100644 (file)
@@ -38,6 +38,7 @@
 #include <functional>
 #include <memory>
 #include <mutex>
+#include <thread>
 #include <condition_variable>
 #include <system_error>
 #include <exception>
@@ -56,10 +57,13 @@ namespace std
 
   /// Error code for futures
   enum class future_errc
-  { broken_promise, future_already_retrieved, promise_already_satisfied };
+  {
+    broken_promise,
+    future_already_retrieved,
+    promise_already_satisfied,
+    no_state
+  };
 
-  // TODO: requires concepts
-  // concept_map ErrorCodeEnum<future_errc> { }
   template<>
     struct is_error_code_enum<future_errc> : public true_type { };
 
@@ -83,8 +87,8 @@ namespace std
     error_code                         _M_code;
 
   public:
-    explicit future_error(future_errc __ec)
-    : logic_error("std::future_error"), _M_code(make_error_code(__ec))
+    explicit future_error(error_code __ec)
+    : logic_error("std::future_error"), _M_code(__ec)
     { }
 
     virtual ~future_error() throw();
@@ -98,17 +102,30 @@ namespace std
 
   // Forward declarations.
   template<typename _Res>
-    class unique_future;
+    class future;
 
   template<typename _Res>
     class shared_future;
 
-  template<typename> 
+  template<typename _Res>
+    class atomic_future;
+
+  template<typename _Signature> 
     class packaged_task;
 
   template<typename _Res>
     class promise;
 
+  enum class launch { any, async, sync };
+
+  template<typename _Fn, typename... _Args>
+    future<typename _Fn::result_type>
+    async(launch __policy, _Fn&& __fn, _Args&&... __args);
+
+  template<typename _Fn, typename... _Args>
+    future<typename _Fn::result_type>
+    async(_Fn&& __fn, _Args&&... __args);
+
 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
   && defined(_GLIBCXX_ATOMIC_BUILTINS_4)
 
@@ -124,9 +141,7 @@ namespace std
       _Result_base(const _Result_base&) = delete;
       _Result_base& operator=(const _Result_base&) = delete;
 
-      // _M_destroy() allows derived classes to control deallocation,
-      // which will be needed when allocator support is added to promise.
-      // See http://gcc.gnu.org/ml/libstdc++/2009-06/msg00032.html
+      // _M_destroy() allows derived classes to control deallocation
       virtual void _M_destroy() = 0;
 
       struct _Deleter
@@ -183,7 +198,6 @@ namespace std
        void* _M_addr() { return static_cast<void*>(&_M_storage); }
     };
 
-
     // TODO: use template alias when available
     /*
       template<typename _Res>
@@ -196,6 +210,50 @@ namespace std
        typedef unique_ptr<_Res, _Result_base::_Deleter> type;
       };
 
+    // TODO: use when allocator_arg_t available
+    /*
+    /// Result_alloc.
+    template<typename _Res, typename _Alloc>
+      struct _Result_alloc : _Result<_Res>
+      {
+        typedef typename _Alloc::template rebind<_Result_alloc>::other
+          __allocator_type;
+
+        explicit
+       _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _M_alloc(__a)
+        { }
+       
+      private:
+       void _M_destroy()
+        {
+          __allocator_type __a(_M_alloc);
+          __a.destroy(this);
+          __a.deallocate(this, 1);
+        }
+
+        __allocator_type _M_alloc;
+    };
+
+    template<typename _Res, typename _Allocator>
+      static typename _Ptr<_Result_alloc<_Res, _Allocator>>::type
+      _S_allocate_result(const _Allocator& __a)
+      {
+        typedef _Result_alloc<_Res, _Allocator>        __result_type;
+        typename __result_type::__allocator_type __a2(__a);
+        __result_type* __p = __a2.allocate(1);
+        __try
+        {
+          __a2.construct(__p, __a);
+        }
+        __catch(...)
+        {
+          __a2.deallocate(__p, 1);
+          __throw_exception_again;
+        }
+        return typename _Ptr<__result_type>::type(__p);
+      }
+    */
+
 
     /// Shared state between a promise and one or more associated futures.
     class _State
@@ -206,6 +264,7 @@ namespace std
       mutex                    _M_mutex;
       condition_variable       _M_cond;
       atomic_flag              _M_retrieved;
+      once_flag                        _M_once;
 
     public:
       _State() : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT) { }
@@ -213,30 +272,13 @@ namespace std
       _State(const _State&) = delete;
       _State& operator=(const _State&) = delete;
 
-      bool
-      is_ready()
-      { return _M_get() != 0; }
-
-      bool
-      has_exception()
-      {
-       _Result_base* const __res = _M_get();
-       return __res && !(__res->_M_error == 0);
-      }
-
-      bool
-      has_value()
-      {
-       _Result_base* const __res = _M_get();
-       return __res && (__res->_M_error == 0);
-      }
-
       _Result_base&
       wait()
       {
+       _M_run_deferred();
        unique_lock<mutex> __lock(_M_mutex);
        if (!_M_ready())
-         _M_cond.wait(__lock, std::bind(&_State::_M_ready, this));
+         _M_cond.wait(__lock, std::bind<bool>(&_State::_M_ready, this));
        return *_M_result;
       }
 
@@ -245,7 +287,7 @@ namespace std
         wait_for(const chrono::duration<_Rep, _Period>& __rel)
         {
          unique_lock<mutex> __lock(_M_mutex);
-         auto __bound = std::bind(&_State::_M_ready, this);
+         auto __bound = std::bind<bool>(&_State::_M_ready, this);
          return _M_ready() || _M_cond.wait_for(__lock, __rel, __bound);
        }
 
@@ -254,20 +296,20 @@ namespace std
         wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
         {
          unique_lock<mutex> __lock(_M_mutex);
-         auto __bound = std::bind(&_State::_M_ready, this);
+         auto __bound = std::bind<bool>(&_State::_M_ready, this);
          return _M_ready() || _M_cond.wait_until(__lock, __abs, __bound);
        }
 
       void
-      _M_set_result(_Ptr_type __res)
+      _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false)
       {
-       {
-         lock_guard<mutex> __lock(_M_mutex);
-         if (_M_ready())
-           __throw_future_error(int(future_errc::promise_already_satisfied));
-         _M_result.swap(__res);
-       }
-       _M_cond.notify_all();
+        bool __set = __ignore_failure;
+        // all calls to this function are serialized,
+        // side-effects of invoking __res only happen once
+        call_once(_M_once, mem_fn(&_State::_M_do_set), this, ref(__res),
+            ref(__set));
+        if (!__set)
+          __throw_future_error(int(future_errc::promise_already_satisfied));
       }
 
       void
@@ -275,7 +317,7 @@ namespace std
       {
        if (static_cast<bool>(__res))
          {
-           future_errc __ec(future_errc::broken_promise); // XXX
+           error_code __ec(make_error_code(future_errc::broken_promise));
            __res->_M_error = copy_exception(future_error(__ec));
            {
              lock_guard<mutex> __lock(_M_mutex);
@@ -285,7 +327,7 @@ namespace std
          }
       }
 
-      // Called when this object is passed to a unique_future.
+      // Called when this object is passed to a future.
       void
       _M_set_retrieved_flag()
       {
@@ -293,16 +335,114 @@ namespace std
          __throw_future_error(int(future_errc::future_already_retrieved));
       }
 
+      template<typename _Res, typename _Arg>
+        struct _Setter;
+
+      // set lvalues
+      template<typename _Res, typename _Arg>
+        struct _Setter<_Res, _Arg&>
+        {
+          // check this is only used by promise<R>::set_value(const R&)
+          // or promise<R>::set_value(R&)
+          static_assert(is_same<_Res, _Arg&>::value  // promise<R&>
+              || is_same<const _Res, _Arg>::value,  // promise<R>
+              "Invalid specialisation");
+
+          typename promise<_Res>::_Ptr_type operator()()
+          {
+            _State::_S_check(_M_promise->_M_future);
+            _M_promise->_M_storage->_M_set(_M_arg);
+            return std::move(_M_promise->_M_storage);
+          }
+          promise<_Res>*    _M_promise;
+          _Arg&             _M_arg;
+        };
+
+      // set rvalues
+      template<typename _Res>
+        struct _Setter<_Res, _Res&&>
+        {
+          typename promise<_Res>::_Ptr_type operator()()
+          {
+            _State::_S_check(_M_promise->_M_future);
+            _M_promise->_M_storage->_M_set(std::move(_M_arg));
+            return std::move(_M_promise->_M_storage);
+          }
+          promise<_Res>*    _M_promise;
+          _Res&             _M_arg;
+        };
+
+      struct __exception_ptr_tag { };
+
+      // set exceptions
+      template<typename _Res>
+        struct _Setter<_Res, __exception_ptr_tag>
+        {
+          typename promise<_Res>::_Ptr_type operator()()
+          {
+            _State::_S_check(_M_promise->_M_future);
+            _M_promise->_M_storage->_M_error = _M_ex;
+            return std::move(_M_promise->_M_storage);
+          }
+
+          promise<_Res>*   _M_promise;
+          exception_ptr&    _M_ex;
+        };
+
+      template<typename _Res, typename _Arg>
+        static _Setter<_Res, _Arg&&>
+        __setter(promise<_Res>* __prom, _Arg&& __arg)
+        {
+          return _Setter<_Res, _Arg&&>{ __prom, __arg };
+        }
+
+      template<typename _Res>
+        static _Setter<_Res, __exception_ptr_tag>
+        __setter(exception_ptr& __ex, promise<_Res>* __prom)
+        {
+          return _Setter<_Res, __exception_ptr_tag>{ __prom, __ex };
+        }
+
+      static _Setter<void, void>
+      __setter(promise<void>* __prom);
+
+      template<typename _Tp>
+        static bool
+        _S_check(const shared_ptr<_Tp>& __p)
+        {
+          if (!static_cast<bool>(__p))
+            __throw_future_error((int)future_errc::no_state);
+        }
+
     private:
-      _Result_base*
-      _M_get()
+      void
+      _M_do_set(function<_Ptr_type()>& __f, bool& __set)
       {
-       lock_guard<mutex> __lock(_M_mutex);
-       return _M_result.get();
+        _Ptr_type __res = __f();
+        {
+          lock_guard<mutex> __lock(_M_mutex);
+          _M_result.swap(__res);
+        }
+        _M_cond.notify_all();
+        __set = true;
       }
 
       bool _M_ready() const { return static_cast<bool>(_M_result); }
+
+      virtual void _M_run_deferred() { }
     };
+
+    template<typename _Res>
+      class _Deferred_state;
+
+    template<typename _Res>
+      class _Async_state;
+
+    template<typename _Signature>
+      class _Task_state;
+
+    template<typename _StateT, typename _Res = typename _StateT::_Res_type>
+      struct _Task_setter;
   };
 
   inline __future_base::_Result_base::~_Result_base() = default;
@@ -313,9 +453,13 @@ namespace std
     {
       _Result() : _M_value_ptr() { }
 
+      void _M_set(_Res& __res) { _M_value_ptr = &__res; }
+
+      _Res& _M_get() { return *_M_value_ptr; }
+
+    private:
       _Res*                    _M_value_ptr;
       
-    private:
       void _M_destroy() { delete this; }
     };
 
@@ -328,7 +472,7 @@ namespace std
     };
 
 
-  /// Common implementation for unique_future and shared_future.
+  /// Common implementation for future and shared_future.
   template<typename _Res>
     class __basic_future : public __future_base
     {
@@ -344,134 +488,190 @@ namespace std
       __basic_future(const __basic_future&) = delete;
       __basic_future& operator=(const __basic_future&) = delete;
 
-      // Functions to check state and wait for ready.
-      bool 
-      is_ready() const { return this->_M_state->is_ready(); }
-
-      bool 
-      has_exception() const { return this->_M_state->has_exception(); }
-
       bool 
-      has_value() const { return this->_M_state->has_value(); }
+      valid() const { return static_cast<bool>(_M_state); }
 
       void 
-      wait() const { this->_M_state->wait(); }
+      wait() const { _M_state->wait(); }
 
       template<typename _Rep, typename _Period>
         bool
         wait_for(const chrono::duration<_Rep, _Period>& __rel) const
-        { return this->_M_state->wait_for(__rel); }
+        { return _M_state->wait_for(__rel); }
 
       template<typename _Clock, typename _Duration>
         bool
         wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const
-        { return this->_M_state->wait_until(__abs); }
+        { return _M_state->wait_until(__abs); }
 
     protected:
       /// Wait for the state to be ready and rethrow any stored exception
       __result_type
       _M_get_result()
       {
-        _Result_base& __res = this->_M_state->wait();
+        _Result_base& __res = _M_state->wait();
         if (!(__res._M_error == 0))
           rethrow_exception(__res._M_error);
         return static_cast<__result_type>(__res);
       }
 
-      // Construction of a unique_future by promise::get_future()
+      void _M_swap(__basic_future& __that)
+      {
+        _M_state.swap(__that._M_state);
+      }
+
+      // Construction of a future by promise::get_future()
       explicit
       __basic_future(const __state_type& __state) : _M_state(__state)
       {
-        if (static_cast<bool>(this->_M_state))
-          this->_M_state->_M_set_retrieved_flag();
-        else
-          __throw_future_error(int(future_errc::future_already_retrieved));
+        _State::_S_check(_M_state);
+        _M_state->_M_set_retrieved_flag();
       }
 
       // Copy construction from a shared_future
       explicit
       __basic_future(const shared_future<_Res>&);
 
-      // Move construction from a unique_future
+      // Move construction from a shared_future
       explicit
-      __basic_future(unique_future<_Res>&&);
+      __basic_future(shared_future<_Res>&&);
+
+      // Move construction from a future
+      explicit
+      __basic_future(future<_Res>&&);
+
+      __basic_future() { }
+
+      struct _Reset
+      {
+        explicit _Reset(__basic_future& __fut) : _M_fut(__fut) { }
+        ~_Reset() { _M_fut._M_state.reset(); }
+        __basic_future& _M_fut;
+      };
     };
 
 
-  /// Primary template for unique_future.
+  /// Primary template for future.
   template<typename _Res>
-    class unique_future : public __basic_future<_Res>
+    class future : public __basic_future<_Res>
     {
       friend class promise<_Res>;
+      template<typename> friend class packaged_task;
+      template<typename _Fn, typename... _Args>
+        friend future<typename _Fn::result_type>
+        async(launch, _Fn&&, _Args&&...);
 
       typedef __basic_future<_Res> _Base_type;
       typedef typename _Base_type::__state_type __state_type;
 
       explicit
-      unique_future(const __state_type& __state) : _Base_type(__state) { }
+      future(const __state_type& __state) : _Base_type(__state) { }
 
     public:
+      future() : _Base_type() { }
+
       /// Move constructor
-      unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+      future(future&& __uf) : _Base_type(std::move(__uf)) { }
 
       // Disable copying
-      unique_future(const unique_future&) = delete;
-      unique_future& operator=(const unique_future&) = delete;
+      future(const future&) = delete;
+      future& operator=(const future&) = delete;
+
+      future& operator=(future&& __fut)
+      {
+        future(std::move(__fut))._M_swap(*this);
+        return *this;
+      }
 
       /// Retrieving the value
-      _Res&&
+      _Res
       get()
-      { return std::move(this->_M_get_result()._M_value()); }
+      {
+        typename _Base_type::_Reset __reset(*this);
+        return std::move(this->_M_get_result()._M_value());
+      }
     };
  
-  /// Partial specialization for unique_future<R&>
+  /// Partial specialization for future<R&>
   template<typename _Res>
-    class unique_future<_Res&> : public __basic_future<_Res&>
+    class future<_Res&> : public __basic_future<_Res&>
     {
       friend class promise<_Res&>;
+      template<typename> friend class packaged_task;
+      template<typename _Fn, typename... _Args>
+        friend future<typename _Fn::result_type>
+        async(launch, _Fn&&, _Args&&...);
 
       typedef __basic_future<_Res&> _Base_type;
       typedef typename _Base_type::__state_type __state_type;
 
       explicit
-      unique_future(const __state_type& __state) : _Base_type(__state) { }
+      future(const __state_type& __state) : _Base_type(__state) { }
 
     public:
+      future() : _Base_type() { }
+
       /// Move constructor
-      unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+      future(future&& __uf) : _Base_type(std::move(__uf)) { }
 
       // Disable copying
-      unique_future(const unique_future&) = delete;
-      unique_future& operator=(const unique_future&) = delete;
+      future(const future&) = delete;
+      future& operator=(const future&) = delete;
+
+      future& operator=(future&& __fut)
+      {
+        future(std::move(__fut))._M_swap(*this);
+        return *this;
+      }
 
       /// Retrieving the value
       _Res& 
-      get() { return *this->_M_get_result()._M_value_ptr; }
+      get()
+      {
+        typename _Base_type::_Reset __reset(*this);
+        return this->_M_get_result()._M_get();
+      }
     };
 
-  /// Explicit specialization for unique_future<void>
+  /// Explicit specialization for future<void>
   template<>
-    class unique_future<void> : public __basic_future<void>
+    class future<void> : public __basic_future<void>
     {
       friend class promise<void>;
+      template<typename> friend class packaged_task;
+      template<typename _Fn, typename... _Args>
+        friend future<typename _Fn::result_type>
+        async(launch, _Fn&&, _Args&&...);
 
       typedef __basic_future<void> _Base_type;
       typedef typename _Base_type::__state_type __state_type;
 
       explicit
-      unique_future(const __state_type& __state) : _Base_type(__state) { }
+      future(const __state_type& __state) : _Base_type(__state) { }
 
     public:
+      future() : _Base_type() { }
+
       /// Move constructor
-      unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+      future(future&& __uf) : _Base_type(std::move(__uf)) { }
 
       // Disable copying
-      unique_future(const unique_future&) = delete;
-      unique_future& operator=(const unique_future&) = delete;
+      future(const future&) = delete;
+      future& operator=(const future&) = delete;
+
+      future& operator=(future&& __fut)
+      {
+        future(std::move(__fut))._M_swap(*this);
+        return *this;
+      }
 
       /// Retrieving the value
       void 
-      get() { this->_M_get_result(); }
+      get()
+      {
+        typename _Base_type::_Reset __reset(*this);
+        this->_M_get_result();
+      }
     };
 
 
@@ -482,20 +682,37 @@ namespace std
       typedef __basic_future<_Res> _Base_type;
 
     public:
+      shared_future() : _Base_type() { }
+
       /// Copy constructor
       shared_future(const shared_future& __sf) : _Base_type(__sf) { }
 
-      /// Construct from a unique_future rvalue
-      shared_future(unique_future<_Res>&& __uf)
+      /// Construct from a future rvalue
+      shared_future(future<_Res>&& __uf)
       : _Base_type(std::move(__uf))
       { }
 
-      shared_future& operator=(const shared_future&) = delete;
+      /// Construct from a shared_future rvalue
+      shared_future(shared_future&& __sf)
+      : _Base_type(std::move(__sf))
+      { }
+
+      shared_future& operator=(const shared_future& __sf)
+      {
+        shared_future(__sf)._M_swap(*this);
+        return *this;
+      }
+
+      shared_future& operator=(shared_future&& __sf)
+      {
+        shared_future(std::move(__sf))._M_swap(*this);
+        return *this;
+      }
 
       /// Retrieving the value
       const _Res&
       get()
-      { 
+      {
        typename _Base_type::__result_type __r = this->_M_get_result();
        _Res& __rs(__r._M_value());
        return __rs;
@@ -509,19 +726,36 @@ namespace std
       typedef __basic_future<_Res&>           _Base_type;
 
     public:
+      shared_future() : _Base_type() { }
+
       /// Copy constructor
       shared_future(const shared_future& __sf) : _Base_type(__sf) { }
 
-      /// Construct from a unique_future rvalue
-      shared_future(unique_future<_Res&>&& __uf)
+      /// Construct from a future rvalue
+      shared_future(future<_Res&>&& __uf)
       : _Base_type(std::move(__uf))
       { }
 
-      shared_future& operator=(const shared_future&) = delete;
+      /// Construct from a shared_future rvalue
+      shared_future(shared_future&& __sf)
+      : _Base_type(std::move(__sf))
+      { }
+
+      shared_future& operator=(const shared_future& __sf)
+      {
+        shared_future(__sf)._M_swap(*this);
+        return *this;
+      }
+
+      shared_future& operator=(shared_future&& __sf)
+      {
+        shared_future(std::move(__sf))._M_swap(*this);
+        return *this;
+      }
 
       /// Retrieving the value
       _Res& 
-      get() { return *this->_M_get_result()._M_value_ptr; }
+      get() { return this->_M_get_result()._M_get(); }
     };
 
   /// Explicit specialization for shared_future<void>
@@ -531,15 +765,32 @@ namespace std
       typedef __basic_future<void> _Base_type;
 
     public:
+      shared_future() : _Base_type() { }
+
       /// Copy constructor
       shared_future(const shared_future& __sf) : _Base_type(__sf) { }
 
-      /// Construct from a unique_future rvalue
-      shared_future(unique_future<void>&& __uf)
+      /// Construct from a future rvalue
+      shared_future(future<void>&& __uf)
       : _Base_type(std::move(__uf))
       { }
 
-      shared_future& operator=(const shared_future&) = delete;
+      /// Construct from a shared_future rvalue
+      shared_future(shared_future&& __sf)
+      : _Base_type(std::move(__sf))
+      { }
+
+      shared_future& operator=(const shared_future& __sf)
+      {
+        shared_future(__sf)._M_swap(*this);
+        return *this;
+      }
+
+      shared_future& operator=(shared_future&& __sf)
+      {
+        shared_future(std::move(__sf))._M_swap(*this);
+        return *this;
+      }
 
       // Retrieving the value
       void 
@@ -553,7 +804,12 @@ namespace std
     { }
 
   template<typename _Res>
-    __basic_future<_Res>::__basic_future(unique_future<_Res>&& __uf)
+    __basic_future<_Res>::__basic_future(shared_future<_Res>&& __sf)
+    : _M_state(std::move(__sf._M_state))
+    { }
+
+  template<typename _Res>
+    __basic_future<_Res>::__basic_future(future<_Res>&& __uf)
     : _M_state(std::move(__uf._M_state))
     { }
 
@@ -562,17 +818,17 @@ namespace std
   template<typename _Res>
     class promise
     {
-      template<typename> friend class packaged_task;
-
       typedef __future_base::_State            _State;
-      typedef __future_base::_Result<_Res>     result_type;
+      typedef __future_base::_Result<_Res>     _Res_type;
+      typedef typename __future_base::_Ptr<_Res_type>::type _Ptr_type;
+      template<typename, typename> friend class _State::_Setter;
       
       shared_ptr<_State>                        _M_future;
-      typename __future_base::_Ptr<result_type>::type  _M_storage;
+      _Ptr_type                                 _M_storage;
 
     public:
       promise()
-      : _M_future(std::make_shared<_State>()), _M_storage(new result_type())
+      : _M_future(std::make_shared<_State>()), _M_storage(new _Res_type())
       { }
 
       promise(promise&& __rhs)
@@ -580,14 +836,14 @@ namespace std
       _M_storage(std::move(__rhs._M_storage))
       { }
 
-      // TODO: requires allocator concepts
+      // TODO: needs allocator_arg_t
       /*
       template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator& __a);
-
-      template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
-       */
+        promise(allocator_arg_t, const _Allocator& __a)
+        : _M_future(std::allocate_shared<_State>(__a)),
+        _M_storage(__future_base::_S_allocate_result<_Res>(__a))
+        { }
+      */
 
       promise(const promise&) = delete;
 
@@ -615,54 +871,48 @@ namespace std
       }
 
       // Retrieving the result
-      unique_future<_Res>
+      future<_Res>
       get_future()
-      { return unique_future<_Res>(_M_future); }
+      { return future<_Res>(_M_future); }
 
       // Setting the result
       void
       set_value(const _Res& __r)
       {
-        if (!_M_satisfied())
-          _M_storage->_M_set(__r);
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(this, __r);
+        _M_future->_M_set_result(std::move(__setter));
       }
 
       void
       set_value(_Res&& __r)
       {
-        if (!_M_satisfied())
-          _M_storage->_M_set(std::move(__r));
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(this, std::move(__r));
+        _M_future->_M_set_result(std::move(__setter));
       }
 
       void
       set_exception(exception_ptr __p)
       {
-        if (!_M_satisfied())
-          _M_storage->_M_error = __p;
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(__p, this);
+        _M_future->_M_set_result(std::move(__setter));
       }
-
-    private:
-      bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
     };
 
   /// Partial specialization for promise<R&>
   template<typename _Res>
     class promise<_Res&>
     {
-      template<typename> friend class packaged_task;
       typedef __future_base::_State            _State;
-      typedef __future_base::_Result<_Res&> result_type;
+      typedef __future_base::_Result<_Res&>    _Res_type;
+      typedef typename __future_base::_Ptr<_Res_type>::type _Ptr_type;
+      template<typename, typename> friend class _State::_Setter;
 
       shared_ptr<_State>                        _M_future;
-      typename __future_base::_Ptr<result_type>::type  _M_storage;
+      _Ptr_type                                 _M_storage;
 
     public:
       promise()
-      : _M_future(std::make_shared<_State>()), _M_storage(new result_type())
+      : _M_future(std::make_shared<_State>()), _M_storage(new _Res_type())
       { }
 
       promise(promise&& __rhs)
@@ -670,14 +920,14 @@ namespace std
        _M_storage(std::move(__rhs._M_storage))
       { }
 
-      // TODO: requires allocator concepts
+      // TODO: needs allocator_arg_t
       /*
       template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator& __a);
-
-      template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
-       */
+        promise(allocator_arg_t, const _Allocator& __a)
+        : _M_future(std::allocate_shared<_State>(__a)),
+        _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
+        { }
+      */
 
       promise(const promise&) = delete;
 
@@ -705,46 +955,42 @@ namespace std
       }
 
       // Retrieving the result
-      unique_future<_Res&>
+      future<_Res&>
       get_future()
-      { return unique_future<_Res&>(_M_future); }
+      { return future<_Res&>(_M_future); }
 
       // Setting the result
       void
       set_value(_Res& __r)
       {
-        if (!_M_satisfied())
-          _M_storage->_M_value_ptr = &__r;
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(this, __r);
+        _M_future->_M_set_result(std::move(__setter));
       }
 
       void
       set_exception(exception_ptr __p)
       {
-        if (!_M_satisfied())
-          _M_storage->_M_error = __p;
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(__p, this);
+        _M_future->_M_set_result(std::move(__setter));
       }
-
-    private:
-      bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
     };
 
   /// Explicit specialization for promise<void>
   template<>
     class promise<void>
     {
-      template<typename> friend class packaged_task;
       typedef __future_base::_State            _State;
-      typedef __future_base::_Result<void>     result_type;
+      typedef __future_base::_Result<void>     _Res_type;
+      typedef typename __future_base::_Ptr<_Res_type>::type _Ptr_type;
+      template<typename, typename> friend class _State::_Setter;
 
-      shared_ptr<__future_base::_State>                 _M_future;
-      typename __future_base::_Ptr<result_type>::type   _M_storage;
+      shared_ptr<_State>                        _M_future;
+      _Ptr_type                                 _M_storage;
 
     public:
       promise()
       : _M_future(std::make_shared<_State>()),
-       _M_storage(new result_type())
+       _M_storage(new _Res_type())
       { }
 
       promise(promise&& __rhs)
@@ -752,14 +998,15 @@ namespace std
       _M_storage(std::move(__rhs._M_storage))
       { }
 
-      // TODO: requires allocator concepts
-      /*
-      template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator& __a);
 
+      // TODO: needs allocator_arg_t
+      /*
       template<typename _Allocator>
-        promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
-       */
+        promise(allocator_arg_t, const _Allocator& __a)
+        : _M_future(std::allocate_shared<_State>(__a)),
+        _M_storage(__future_base::_S_allocate_result<void>(__a))
+        { }
+      */
 
       promise(const promise&) = delete;
 
@@ -787,69 +1034,137 @@ namespace std
       }
 
       // Retrieving the result
-      unique_future<void>
+      future<void>
       get_future()
-      { return unique_future<void>(_M_future); }
+      { return future<void>(_M_future); }
 
       // Setting the result
+      void set_value();
+
       void
-      set_value()
+      set_exception(exception_ptr __p)
       {
-        _M_future->_M_set_result(std::move(_M_storage));
+        auto __setter = _State::__setter(__p, this);
+        _M_future->_M_set_result(std::move(__setter));
       }
+    };
 
-      void
-      set_exception(exception_ptr __p)
+  // set void
+  template<>
+    struct __future_base::_State::_Setter<void, void>
+    {
+      promise<void>::_Ptr_type operator()()
       {
-        if (!_M_satisfied())
-          _M_storage->_M_error = __p;
-        _M_future->_M_set_result(std::move(_M_storage));
+        _State::_S_check(_M_promise->_M_future);
+        return std::move(_M_promise->_M_storage);
       }
 
-    private:
-      bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
+      promise<void>*    _M_promise;
     };
 
-  // TODO: requires allocator concepts
+  inline __future_base::_State::_Setter<void, void>
+  __future_base::_State::__setter(promise<void>* __prom)
+  {
+    return _Setter<void, void>{ __prom };
+  }
+
+  inline void
+  promise<void>::set_value()
+  {
+    auto __setter = _State::__setter(this);
+    _M_future->_M_set_result(std::move(__setter));
+  }
+
+  // TODO: needs allocators
   /*
   template<typename _Res, class Alloc>
-    concept_map UsesAllocator<promise<_Res>, Alloc>
-    {
-      typedef Alloc allocator_type;
-    }
-   */
-  /// Primary template.
-  template<typename _Res, typename... _ArgTypes>
-    struct _Run_task
+    struct uses_allocator<promise<_Res>, Alloc> : true_type  { };
+  */
+
+
+  template<typename _StateT, typename _Res>
+    struct __future_base::_Task_setter
     {
-      static void
-      _S_run(promise<_Res>& __p, function<_Res(_ArgTypes...)>& __f,
-            _ArgTypes... __args)
+      typename _StateT::_Ptr_type operator()()
       {
-        __p.set_value(__f(std::forward<_ArgTypes>(__args)...));
+        __try {
+          _M_state->_M_result->_M_set(_M_fn());
+        } __catch(...) {
+          _M_state->_M_result->_M_error = current_exception();
+        }
+        return std::move(_M_state->_M_result);
       }
+      _StateT*                  _M_state;
+      std::function<_Res()>     _M_fn;
     };
 
-  /// Specialization used by packaged_task<void(...)>
-  template<typename... _ArgTypes>
-    struct _Run_task<void, _ArgTypes...>
+  template<typename _StateT>
+    struct __future_base::_Task_setter<_StateT, void>
     {
-      static void
-      _S_run(promise<void>& __p, function<void(_ArgTypes...)>& __f,
-            _ArgTypes... __args)
+      typename _StateT::_Ptr_type operator()()
       {
-        __f(std::forward<_ArgTypes>(__args)...);
-        __p.set_value();
+        __try {
+          _M_fn();
+        } __catch(...) {
+          _M_state->_M_result->_M_error = current_exception();
+        }
+        return std::move(_M_state->_M_result);
       }
+      _StateT*                  _M_state;
+      std::function<void()>     _M_fn;
     };
 
+  template<typename _Res, typename... _Args>
+    struct __future_base::_Task_state<_Res(_Args...)> : __future_base::_State
+    {
+      typedef _Res _Res_type;
+
+      _Task_state(std::function<_Res(_Args...)> __task)
+      : _M_result(new _Result<_Res>()), _M_task(std::move(__task))
+      { }
+
+      // TODO: needs allocator_arg_t
+      /*
+      template<typename _Func, typename _Alloc>
+        _Task_state(_Func&& __task, const _Alloc& __a)
+        : _M_result(_S_allocate_result<_Res>(__a))
+        , _M_task(allocator_arg, __a, std::move(__task))
+        { }
+      */
+
+      void
+      _M_run(_Args... __args)
+      {
+        // bound arguments decay so wrap lvalue references
+        auto __bound = std::bind<_Res>(_M_task,
+            _S_maybe_wrap_ref(std::forward<_Args>(__args))...);
+        _Task_setter<_Task_state> __setter{ this, std::move(__bound) };
+        _M_set_result(std::move(__setter));
+      }
+
+      template<typename, typename> friend class _Task_setter;
+      typedef typename __future_base::_Ptr<_Result<_Res>>::type _Ptr_type;
+      _Ptr_type _M_result;
+      std::function<_Res(_Args...)> _M_task;
+
+      template<typename _Tp>
+        static reference_wrapper<_Tp>
+        _S_maybe_wrap_ref(_Tp& __t)
+        { return std::ref(__t); }
+
+      template<typename _Tp>
+        static typename enable_if<!is_lvalue_reference<_Tp>::value,
+                        _Tp>::type&&
+        _S_maybe_wrap_ref(_Tp&& __t)
+        { return std::forward<_Tp>(__t); }
+    };
 
   /// packaged_task
   template<typename _Res, typename... _ArgTypes>
     class packaged_task<_Res(_ArgTypes...)>
     {
-      function<_Res(_ArgTypes...)>   _M_task;
-      promise<_Res>                  _M_promise;
+      typedef __future_base::_Task_state<_Res(_ArgTypes...)>  _State_type;
+      shared_ptr<_State_type>                   _M_state;
 
     public:
       typedef _Res result_type;
@@ -859,31 +1174,35 @@ namespace std
 
       template<typename _Fn>
         explicit
-        packaged_task(const _Fn& __fn) : _M_task(__fn) { }
+        packaged_task(const _Fn& __fn)
+        : _M_state(std::make_shared<_State_type>(__fn))
+        { }
 
       template<typename _Fn>
         explicit
-        packaged_task(_Fn&& __fn) : _M_task(std::move(__fn)) { }
+        packaged_task(_Fn&& __fn)
+        : _M_state(std::make_shared<_State_type>(std::move(__fn)))
+        { }
 
       explicit
-      packaged_task(_Res(*__fn)(_ArgTypes...)) : _M_task(__fn) { }
+      packaged_task(_Res(*__fn)(_ArgTypes...))
+      : _M_state(std::make_shared<_State_type>(__fn))
+      { }
 
-      // TODO: requires allocator concepts
+      // TODO: needs allocator_arg_t
       /*
       template<typename _Fn, typename _Allocator>
         explicit
         packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn __fn)
-        : _M_task(__tag, __a, __fn), _M_promise(__tag, __a)
-        { }
-
-      template<typename _Fn, typename _Allocator>
-        explicit
-        packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn&& __fn)
-        : _M_task(__tag, __a, std::move(__fn)), _M_promise(__tag, __a)
+        : _M_state(std::allocate_shared<_State_type>(__a, std::move(__fn)))
         { }
-       */
+      */
 
-      ~packaged_task() = default;
+      ~packaged_task()
+      {
+        if (static_cast<bool>(_M_state) && !_M_state.unique())
+          _M_state->_M_break_promise(std::move(_M_state->_M_result));
+      }
 
       // No copy
       packaged_task(packaged_task&) = delete;
@@ -901,50 +1220,114 @@ namespace std
 
       void
       swap(packaged_task& __other)
-      {
-        _M_task.swap(__other._M_task);
-        _M_promise.swap(__other._M_promise);
-      }
+      { _M_state.swap(__other._M_state); }
 
-      explicit operator bool() const { return static_cast<bool>(_M_task); }
+      explicit operator bool() const { return static_cast<bool>(_M_state); }
 
       // Result retrieval
-      unique_future<_Res>
+      future<_Res>
       get_future()
-      {
-        __try
-        {
-          return _M_promise.get_future();
-        }
-        __catch (const future_error& __e)
-        {
-          if (__e.code() == future_errc::future_already_retrieved)
-            __throw_bad_function_call();
-          __throw_exception_again;
-        }
-      }
+      { return future<_Res>(_M_state); }
 
       // Execution
       void
       operator()(_ArgTypes... __args)
       {
-        if (!static_cast<bool>(_M_task) || _M_promise._M_satisfied())
-          __throw_bad_function_call();
+        __future_base::_State::_S_check(_M_state);
+        _M_state->_M_run(std::forward<_ArgTypes>(__args)...);
+      }
 
-        __try
-        {
-          _Run_task<_Res, _ArgTypes...>::_S_run(_M_promise, _M_task,
-              std::forward<_ArgTypes>(__args)...);
-        }
-        __catch (...)
-        {
-          _M_promise.set_exception(current_exception());
-        }
+      void
+      reset()
+      {
+        __future_base::_State::_S_check(_M_state);
+        packaged_task(std::move(_M_state->_M_task)).swap(*this);
+      }
+    };
+
+  template<typename _Res>
+    class __future_base::_Deferred_state : public __future_base::_State
+    {
+    public:
+      typedef _Res _Res_type;
+
+      explicit
+      _Deferred_state(std::function<_Res()>&& __fn)
+      : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn))
+      { }
+
+    private:
+      template<typename, typename> friend class _Task_setter;
+      typedef typename __future_base::_Ptr<_Result<_Res>>::type _Ptr_type;
+      _Ptr_type _M_result;
+      std::function<_Res()> _M_fn;
+
+      virtual void
+      _M_run_deferred()
+      {
+        _Task_setter<_Deferred_state> __setter{ this, _M_fn };
+        // safe to call multiple times so ignore failure
+        _M_set_result(std::move(__setter), true);
+      }
+    };
+
+  template<typename _Res>
+    class __future_base::_Async_state : public __future_base::_State
+    {
+    public:
+      typedef _Res _Res_type;
+
+      explicit 
+      _Async_state(std::function<_Res()>&& __fn)
+      : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)),
+      _M_thread(mem_fn(&_Async_state::_M_do_run), this)
+      { }
+
+      ~_Async_state() { _M_thread.join(); }
+
+    private:
+      void _M_do_run()
+      {
+        _Task_setter<_Async_state> __setter{ this, std::move(_M_fn) };
+        _M_set_result(std::move(__setter));
       }
 
-      void reset() { promise<_Res>().swap(_M_promise); }
+      template<typename, typename> friend class _Task_setter;
+      typedef typename __future_base::_Ptr<_Result<_Res>>::type _Ptr_type;
+      _Ptr_type _M_result;
+      std::function<_Res()> _M_fn;
+      thread _M_thread;
     };
 
+  template<typename _Fn, typename... _Args>
+    future<typename _Fn::result_type>
+    async(launch __policy, _Fn&& __fn, _Args&&... __args)
+    {
+      typedef typename _Fn::result_type result_type;
+      std::shared_ptr<__future_base::_State> __state;
+      if (__policy == launch::async)
+      {
+        typedef typename __future_base::_Async_state<result_type> _State;
+        __state = std::make_shared<_State>(std::bind<result_type>(
+              std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
+      }
+      else
+      {
+        typedef typename __future_base::_Deferred_state<result_type> _State;
+        __state = std::make_shared<_State>(std::bind<result_type>(
+              std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
+      }
+      return future<result_type>(__state);
+    }
+
+  template<typename _Fn, typename... _Args>
+    future<typename _Fn::result_type>
+    async(_Fn&& __fn, _Args&&... __args)
+    {
+      return async(launch::any, std::forward<_Fn>(__fn),
+          std::forward<_Args>(__args)...);
+    }
+
 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
        // && _GLIBCXX_ATOMIC_BUILTINS_4
 
index d47eccb..c5c3e37 100644 (file)
@@ -103,7 +103,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
   void
   __throw_future_error(int __i)
-  { throw future_error(future_errc(__i)); }
+  { throw future_error(make_error_code(future_errc(__i))); }
 
   void
   __throw_bad_function_call()
@@ -6,7 +6,7 @@
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 #include <future>
 #include <testsuite_hooks.h>
 
-void test01()
-{
-  bool test __attribute__((unused)) = true;
-
-  std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
-
-  VERIFY( !f1.has_exception() );
-
-  p1.set_exception(std::copy_exception(1));
+struct sum {
+  typedef int result_type;
+  int operator()(int i, int& j, const int& k) { return i + j + k; }
+};
 
-  VERIFY( f1.has_exception() );
-}
-
-void test02()
+void test01()
 {
   bool test __attribute__((unused)) = true;
 
-  std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  using namespace std;
 
-  VERIFY( !f1.has_exception() );
+  int a = 1;
+  int b = 10;
+  int c = 100;
+  future<int> f1 = async(launch::any, sum(), a, ref(b), cref(c));
+  future<int> f2 = async(sum(), a, ref(b), cref(c));
 
-  p1.set_value(1);
-
-  VERIFY( !f1.has_exception() );
+  VERIFY( f1.valid() );
+  VERIFY( f2.valid() );
+  int r1 = f1.get();
+  int r2 = f2.get();
+  VERIFY( r1 == r2 );
 }
 
 int main()
 {
   test01();
-  test02();
-
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc
new file mode 100644 (file)
index 0000000..5335dfc
--- /dev/null
@@ -0,0 +1,57 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+struct work {
+  typedef void result_type;
+  void operator()(mutex& m, condition_variable& cv)
+  {
+    unique_lock<mutex> l(m);
+    cv.notify_one();
+  }
+};
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  mutex m;
+  condition_variable cv;
+  unique_lock<mutex> l(m);
+  future<void> f1 = async(launch::async, work(), ref(m), ref(cv));
+  cv.wait(l);
+  f1.get();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
@@ -6,7 +6,7 @@
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 #include <future>
 #include <testsuite_hooks.h>
 
+struct sum {
+  typedef int result_type;
+  int operator()(int i, int& j, const int& k) { return i + j + k; }
+};
+
 void test01()
 {
   bool test __attribute__((unused)) = true;
 
-  std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
-
-  VERIFY( !f1.is_ready() );
+  using namespace std;
 
-  p1.set_value(1);
+  int a = 1;
+  int b = 10;
+  int c = 100;
+  future<int> f1 = async(launch::sync, sum(), a, ref(b), cref(c));
 
-  VERIFY( f1.is_ready() );
+  VERIFY( f1.valid() );
+  VERIFY( f1.get() == 111 );
 }
 
 int main()
index 16a54b4..fe040ec 100644 (file)
@@ -31,9 +31,9 @@ void test01()
 
   typedef std::future_error error_t;
 
-  typedef std::unique_future<int> uniq_t;
-  typedef std::unique_future<int&> uniqr_t;
-  typedef std::unique_future<void> uniqv_t;
+  typedef std::future<int> uniq_t;
+  typedef std::future<int&> uniqr_t;
+  typedef std::future<void> uniqv_t;
 
   typedef std::shared_future<int> shar_t;
   typedef std::shared_future<int&> sharr_t;
@@ -46,4 +46,6 @@ void test01()
   typedef std::packaged_task<int> ptask_t;
   typedef std::packaged_task<int&> ptaskr_t;
   typedef std::packaged_task<void> ptaskv_t;
+
+  using std::async;
 }
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/alloc.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/alloc.cc
new file mode 100644 (file)
index 0000000..2565b61
--- /dev/null
@@ -0,0 +1,52 @@
+// { dg-do compile { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+int f() { return 5; }
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  using std::packaged_task;
+  using std::allocator_arg;
+  using __gnu_test::uneq_allocator;
+
+  uneq_allocator<char> alloc(99);
+
+  packaged_task<int ()> p1(allocator_arg, alloc, f); // { dg-excess-errors "" }
+  VERIFY( static_cast<bool>(p1) );
+  p1();
+  VERIFY( p1.get_future().get() == 5 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 031ce0b..8b724d5 100644 (file)
@@ -33,4 +33,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 32 }
-// { dg-error "deleted function" "" { target *-*-* } 890 }
+// { dg-error "deleted function" "" { target *-*-* } 1209 }
index 65cf9fd..82a330f 100644 (file)
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 889 }
+// { dg-error "deleted function" "" { target *-*-* } 1208 }
index c1bc129..b44891b 100644 (file)
@@ -34,9 +34,10 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::packaged_task<int&(int&)> p1(inc);
-  std::unique_future<int&> f1 = p1.get_future();
+  std::future<int&> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
+  VERIFY( !f1.wait_for(std::chrono::milliseconds(1)) );
 
   int i1 = 0;
 
index a6c9c61..5c6d67b 100644 (file)
@@ -42,8 +42,9 @@ void test01()
     p1.get_future();
     VERIFY( false );
   }
-  catch (std::bad_function_call&)
+  catch (const std::future_error& e)
   {
+    VERIFY( e.code() == std::future_errc::future_already_retrieved );
     test = true;
   }
 
index 2797b06..cce7b54 100644 (file)
@@ -34,12 +34,12 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::packaged_task<int()> p1(zero);
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
   p1();
 
   VERIFY( static_cast<bool>(p1) );
-  VERIFY( f1.has_value() );
+  VERIFY( f1.get() == 0 );
 }
 
 int main()
index fae15dc..e29852c 100644 (file)
@@ -41,8 +41,9 @@ void test01()
   {
     p1(4);
   }
-  catch (std::bad_function_call&)
+  catch (const std::future_error& e)
   {
+    VERIFY( e.code() == std::future_errc::promise_already_satisfied );
     test = true;
   }
 
index 91d4341..7ae6106 100644 (file)
@@ -44,8 +44,9 @@ void test01()
   {
     p1(i1);
   }
-  catch (std::bad_function_call&)
+  catch (const std::future_error& e)
   {
+    VERIFY( e.code() == std::future_errc::promise_already_satisfied );
     test = true;
   }
 
index eefb313..6f0013f 100644 (file)
@@ -31,14 +31,19 @@ void thrower() { throw 0; }
 
 void test01()
 {
-  bool test __attribute__((unused)) = true;
+  bool test = false;
 
   std::packaged_task<void()> p1(thrower);
-  std::unique_future<void> f1 = p1.get_future();
+  std::future<void> f1 = p1.get_future();
 
   p1();
 
-  VERIFY( f1.has_exception() );
+  try {
+    f1.get();
+  } catch (int) {
+    test = true;
+  }
+  VERIFY( test );
 }
 
 int main()
index 66b9f3d..a126c3a 100644 (file)
@@ -36,15 +36,13 @@ void test01()
   using namespace std;
 
   packaged_task<int()> p1(zero);
-  unique_future<int> f1 = p1.get_future();
+  future<int> f1 = p1.get_future();
 
   p1.reset();
   VERIFY( static_cast<bool>(p1) );
 
-  unique_future<int> f2 = p1.get_future();
-  VERIFY( !f2.is_ready() );
+  future<int> f2 = p1.get_future();
 
-  VERIFY( f1.has_exception() );
   try
   {
     f1.get();
index 69ee9a9..e38d047 100644 (file)
 #include <future>
 #include <testsuite_hooks.h>
 
-int zero() { return 0; }
+int iota() { static int i = 0; return i++; }
 
 void test01()
 {
   bool test __attribute__((unused)) = true;
 
-  std::packaged_task<int()> p1(zero);
-  std::unique_future<int> f1 = p1.get_future();
+  std::packaged_task<int()> p1(iota);
+  std::future<int> f1 = p1.get_future();
 
   p1();
   p1.reset();
 
   VERIFY( static_cast<bool>(p1) );
-  VERIFY( f1.has_value() );
+  VERIFY( f1.get() == 0 );
 
-  std::unique_future<int> f2 = p1.get_future();
-  VERIFY( !f2.is_ready() );
+  std::future<int> f2 = p1.get_future();
+  p1();
+  VERIFY( f2.get() == 1 );
 }
 
 int main()
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc
new file mode 100644 (file)
index 0000000..6d53f44
--- /dev/null
@@ -0,0 +1,47 @@
+// { dg-do compile { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+void test01()
+{
+  using std::promise;
+  using std::allocator_arg;
+  using __gnu_test::uneq_allocator;
+
+  uneq_allocator<char> alloc(99);
+
+  promise<int> p1(allocator_arg, alloc); // { dg-excess-errors "" }
+  p1.set_value(5);
+  VERIFY( p1.get_future().get() == 5 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 5434740..229ee3f 100644 (file)
@@ -33,4 +33,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 32 }
-// { dg-error "deleted function" "" { target *-*-* } 608 }
+// { dg-error "deleted function" "" { target *-*-* } 864 }
index 79d2e16..a40ab79 100644 (file)
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 592 }
+// { dg-error "deleted function" "" { target *-*-* } 848 }
index 8b1e139..5fc2cae 100644 (file)
@@ -44,7 +44,7 @@ void test01()
   }
   catch (std::future_error& e)
   {
-    VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+    VERIFY(e.code() == make_error_code(future_errc::no_state));
   }
 }
 
index c5bda4d..5d96e8f 100644 (file)
@@ -45,7 +45,7 @@ void test01()
   }
   catch (future_error& e)
   {
-    VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+    VERIFY(e.code() == make_error_code(future_errc::no_state));
   }
 }
 
index 7e96990..b09e302 100644 (file)
@@ -32,9 +32,9 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int&> p1;
-  std::unique_future<int&> f1 = p1.get_future();
+  std::future<int&> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   int i1 = 0;
 
index e5b8f60..4d2a1ec 100644 (file)
 
 void test01()
 {
-  bool test __attribute__((unused)) = true;
+  bool test = false;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   p1.set_exception(std::copy_exception(0));
 
-  VERIFY( f1.has_exception() );
-  VERIFY( !f1.has_value() );
+  try
+  {
+    f1.get();
+  }
+  catch (int)
+  {
+    test = true;
+  }
+  VERIFY( test );
+  VERIFY( !f1.valid() );
 }
 
 int main()
index 3bbe28d..872a479 100644 (file)
@@ -32,7 +32,7 @@ void test01()
   bool test = false;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
   p1.set_exception(std::copy_exception(0));
 
@@ -66,7 +66,7 @@ void test02()
   bool test = false;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
   p1.set_value(2);
 
@@ -82,8 +82,6 @@ void test02()
     test = true;
   }
 
-  VERIFY( f1.has_value() );
-  VERIFY( !f1.has_exception() );
   VERIFY( test );
 }
 
index 978ef19..9d3f8ea 100644 (file)
@@ -33,9 +33,9 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   p1.set_value(0);
 
@@ -50,15 +50,15 @@ void test02()
   using __gnu_test::rvalstruct;
 
   std::promise<rvalstruct> p1;
-  std::unique_future<rvalstruct> f1 = p1.get_future();
+  std::future<rvalstruct> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   p1.set_value(rvalstruct(1));
 
   rvalstruct r1(f1.get());
 
-  VERIFY( r1.valid );
+  VERIFY( !f1.valid() );
   VERIFY( r1.val == 1 );
 }
 
@@ -68,14 +68,15 @@ void test03()
   bool test __attribute__((unused)) = true;
 
   std::promise<int&> p1;
-  std::unique_future<int&> f1 = p1.get_future();
+  std::future<int&> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   int i1 = 0;
   p1.set_value(i1);
   int& i2 = f1.get();
 
+  VERIFY( !f1.valid() );
   VERIFY( &i1 == &i2 );
 }
 
@@ -84,14 +85,14 @@ void test04()
   bool test __attribute__((unused)) = true;
 
   std::promise<void> p1;
-  std::unique_future<void> f1 = p1.get_future();
+  std::future<void> f1 = p1.get_future();
 
-  VERIFY( !f1.is_ready() );
+  VERIFY( f1.valid() );
 
   p1.set_value();
   f1.get();
 
-  VERIFY( f1.is_ready() );
+  VERIFY( !f1.valid() );
 }
 
 int main()
index 58e2fe8..09c8a52 100644 (file)
@@ -32,7 +32,7 @@ void test01()
   bool test = false;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
   p1.set_value(1);
 
@@ -48,7 +48,7 @@ void test01()
     test = true;
   }
 
-  VERIFY( f1.has_value() );
+  VERIFY( f1.wait_for(std::chrono::milliseconds(1)) );
   VERIFY( f1.get() == 1 );
   VERIFY( test );
 }
@@ -58,7 +58,7 @@ void test02()
   bool test = false;
 
   std::promise<int> p1;
-  std::unique_future<int> f1 = p1.get_future();
+  std::future<int> f1 = p1.get_future();
 
   p1.set_value(3);
 
@@ -74,8 +74,7 @@ void test02()
     test = true;
   }
 
-  VERIFY( f1.has_value() );
-  VERIFY( !f1.has_exception() );
+  VERIFY( f1.wait_for(std::chrono::milliseconds(1)) );
   VERIFY( f1.get() == 3 );
   VERIFY( test );
 }
index 9258196..b94b1b6 100644 (file)
@@ -41,33 +41,33 @@ struct tester
 };
 
 std::promise<tester> pglobal;
-std::unique_future<tester> fglobal = pglobal.get_future();
+std::future<tester> fglobal = pglobal.get_future();
 
 tester::tester(int)
 {
   bool test __attribute__((unused)) = true;
-  VERIFY (!fglobal.is_ready());
+  VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
 }
 
 tester::tester(const tester&)
 {
   bool test __attribute__((unused)) = true;
   // if this copy happens while a mutex is locked next line could deadlock:
-  VERIFY (!fglobal.is_ready());
+  VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
 }
 
 tester& tester::operator=(const tester&)
 {
   bool test __attribute__((unused)) = true;
   // if this copy happens while a mutex is locked next line could deadlock:
-  VERIFY (!fglobal.is_ready());
+  VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
   return *this;
 }
 
 tester::~tester()
 {
   bool test __attribute__((unused)) = true;
-  VERIFY (fglobal.is_ready());
+  VERIFY (fglobal.wait_for(std::chrono::milliseconds(1)));
 }
 
 void test01()
@@ -76,7 +76,7 @@ void test01()
 
   pglobal.set_value( tester(1) );
 
-  VERIFY( fglobal.is_ready() );
+  VERIFY( fglobal.wait_for(std::chrono::milliseconds(1)) );
 }
 
 int main()
index 8bfbdfd..b27ee2b 100644 (file)
@@ -35,8 +35,8 @@ void test01()
   std::promise<int> p2;
   p1.set_value(1);
   p1.swap(p2);
-  VERIFY( !p1.get_future().is_ready() );
-  VERIFY( p2.get_future().is_ready() );
+  VERIFY( !p1.get_future().wait_for(std::chrono::milliseconds(1)) );
+  VERIFY( p2.get_future().wait_for(std::chrono::milliseconds(1)) );
 }
 
 int main()
@@ -1,10 +1,9 @@
-// { dg-do compile }
 // { dg-options "-std=gnu++0x" }
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 
 
 #include <future>
+#include <testsuite_hooks.h>
 
-extern std::shared_future<int>& get();
+std::future<int> get() { return std::promise<int>().get_future(); }
 
 void test01()
 {
   // assign
-  std::shared_future<int>& p1 = get();
-  std::shared_future<int>& p2 = get();
+  std::shared_future<int> p1;
+  std::shared_future<int> p2 = get();
   p1 = p2;
+  VERIFY( p1.valid() );
+  VERIFY( p2.valid() );
+}
+
+int main()
+{
+  test01();
+  return 0;
 }
 
-// { dg-error "used here" "" { target *-*-* } 34 }
-// { dg-error "deleted function" "" { target *-*-* } 493 }
index b1940fa..09af94e 100644 (file)
@@ -25,7 +25,7 @@
 #include <future>
 #include <testsuite_hooks.h>
 
-extern std::unique_future<int>&& get();
+extern std::future<int>&& get();
 
 void test01()
 {
@@ -1,10 +1,9 @@
-// { dg-do compile }
 // { dg-options "-std=gnu++0x" }
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -23,6 +22,7 @@
 
 
 #include <future>
+#include <testsuite_hooks.h>
 #include <testsuite_tr1.h>
 
 void test01()
@@ -30,11 +30,18 @@ void test01()
   using std::shared_future;
   using namespace __gnu_test;
 
-  shared_future<int> p1;            // { dg-error "22: error: no match" }
-  shared_future<int&> p2;           // { dg-error "23: error: no match" }
-  shared_future<void> p3;           // { dg-error "23: error: no match" }
-  shared_future<ClassType> p4;      // { dg-error "28: error: no match" }
-  shared_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
+  bool __attribute__((unused)) test = true;
+
+  shared_future<int> p1;
+  VERIFY( !p1.valid() );
+  shared_future<int&> p2;
+  VERIFY( !p2.valid() );
+  shared_future<void> p3;
+  VERIFY( !p3.valid() );
+  shared_future<ClassType> p4;
+  VERIFY( !p4.valid() );
+  shared_future<AbstractClass&> p5;
+  VERIFY( !p5.valid() );
 }
 
 int main()
@@ -42,4 +49,3 @@ int main()
   test01();
   return 0;
 }
-// { dg-excess-errors "note" }
index 3494a10..bb9b62b 100644 (file)
@@ -28,9 +28,9 @@
 
 void test01()
 {
-  // construct from rvalue unique_future
+  // construct from rvalue future
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::future<int> f1(p1.get_future());
   std::shared_future<int> f2(std::move(f1));
 }
 
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/move_assign.cc
new file mode 100644 (file)
index 0000000..1476049
--- /dev/null
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+std::future<int> get() { return std::promise<int>().get_future(); }
+
+void test01()
+{
+  // assign
+  std::shared_future<int> p1;
+  std::shared_future<int> p2 = get();
+  p1 = std::move(p2);
+  VERIFY( p1.valid() );
+  VERIFY( !p2.valid() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc
deleted file mode 100644 (file)
index 97d3980..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
-// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
-// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
-// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
-// { dg-require-cstdint "" }
-// { dg-require-gthreads "" }
-// { dg-require-atomic-builtins "" }
-
-// Copyright (C) 2009 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3.  If not see
-// <http://www.gnu.org/licenses/>.
-
-
-#include <future>
-#include <testsuite_hooks.h>
-
-void test01()
-{
-  bool test __attribute__((unused)) = true;
-
-  std::promise<int> p1;
-  std::shared_future<int> f1(p1.get_future());
-  std::shared_future<int> f2(f1);
-
-  VERIFY( !f1.has_exception() );
-  VERIFY( !f2.has_exception() );
-
-  p1.set_exception(std::copy_exception(1));
-
-  VERIFY( f1.has_exception() );
-  VERIFY( f2.has_exception() );
-}
-
-void test02()
-{
-  std::promise<int> p1;
-  bool test __attribute__((unused)) = true;
-
-  std::shared_future<int> f1(p1.get_future());
-  std::shared_future<int> f2(f1);
-
-  VERIFY( !f1.has_exception() );
-  VERIFY( !f2.has_exception() );
-
-  p1.set_value(1);
-
-  VERIFY( !f1.has_exception() );
-  VERIFY( !f2.has_exception() );
-}
-
-int main()
-{
-  test01();
-  test02();
-
-  return 0;
-}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc
deleted file mode 100644 (file)
index 8903c82..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
-// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
-// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
-// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
-// { dg-require-cstdint "" }
-// { dg-require-gthreads "" }
-// { dg-require-atomic-builtins "" }
-
-// Copyright (C) 2009 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3.  If not see
-// <http://www.gnu.org/licenses/>.
-
-
-#include <future>
-#include <testsuite_hooks.h>
-
-void test01()
-{
-  bool test __attribute__((unused)) = true;
-
-  std::promise<int> p1;
-  std::shared_future<int> f1(p1.get_future());
-  std::shared_future<int> f2(f1);
-
-  VERIFY( !f1.has_value() );
-  VERIFY( !f2.has_value() );
-
-  p1.set_value(1);
-
-  VERIFY( f1.has_value() );
-  VERIFY( f2.has_value() );
-}
-
-void test02()
-{
-  bool test __attribute__((unused)) = true;
-
-  std::promise<int> p1;
-  std::shared_future<int> f1(p1.get_future());
-  std::shared_future<int> f2(f1);
-
-  VERIFY( !f1.has_value() );
-  VERIFY( !f2.has_value() );
-
-  p1.set_exception(std::copy_exception(1));
-
-  VERIFY( !f1.has_value() );
-  VERIFY( !f2.has_value() );
-}
-
-int main()
-{
-  test01();
-  test02();
-
-  return 0;
-}
@@ -6,7 +6,7 @@
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -31,35 +31,31 @@ void test01()
 {
   bool test __attribute__((unused)) = true;
 
-  std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::shared_future<int> f0;
 
-  VERIFY( !f1.has_value() );
+  VERIFY( !f0.valid() );
 
-  p1.set_value(1);
+  std::promise<int> p1;
+  std::shared_future<int> f1(p1.get_future());
+  std::shared_future<int> f2(f1);
 
-  VERIFY( f1.has_value() );
-}
+  VERIFY( f1.valid() );
+  VERIFY( f2.valid() );
 
-void test02()
-{
-  bool test __attribute__((unused)) = true;
-
-  std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  p1.set_value(1);
 
-  VERIFY( !f1.has_value() );
+  VERIFY( f1.valid() );
+  VERIFY( f2.valid() );
 
-  p1.set_exception(std::copy_exception(1));
+  f1 = std::move(f0);
 
-  VERIFY( !f1.has_value() );
+  VERIFY( !f0.valid() );
+  VERIFY( !f1.valid() );
+  VERIFY( f2.valid() );
 }
 
 int main()
 {
   test01();
-  test02();
-
   return 0;
 }
-
index 69caf12..ecdc27c 100644 (file)
 
 #include <future>
 
-extern std::unique_future<int>& get();
+extern std::future<int>& get();
 
 void test01()
 {
   // assign
-  std::unique_future<int>& p1 = get();
-  std::unique_future<int>& p2 = get();
+  std::future<int>& p1 = get();
+  std::future<int>& p2 = get();
   p1 = p2;
 }
 
 // { dg-error "used here" "" { target *-*-* } 34 }
-// { dg-error "deleted function" "" { target *-*-* } 419 }
+// { dg-error "deleted function" "" { target *-*-* } 578 }
index 43e940c..c76075d 100644 (file)
 
 #include <future>
 
-extern std::unique_future<int>& get();
+extern std::future<int>& get();
 
 void test01()
 {
   // copy
-  std::unique_future<int>& p1 = get();
-  std::unique_future<int> p2(p1);
+  std::future<int>& p1 = get();
+  std::future<int> p2(p1);
 }
 
 // { dg-error "used here" "" { target *-*-* } 33 }
-// { dg-error "deleted function" "" { target *-*-* } 418 }
+// { dg-error "deleted function" "" { target *-*-* } 577 }
@@ -1,10 +1,9 @@
-// { dg-do compile }
 // { dg-options "-std=gnu++0x" }
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 
 
 #include <future>
+#include <testsuite_hooks.h>
 #include <testsuite_tr1.h>
 
 void test01()
 {
-  using std::unique_future;
+  using std::future;
   using namespace __gnu_test;
 
-  unique_future<int> p1;            // { dg-error "22: error: no match" }
-  unique_future<int&> p2;           // { dg-error "23: error: no match" }
-  unique_future<void> p3;           // { dg-error "23: error: no match" }
-  unique_future<ClassType> p4;      // { dg-error "28: error: no match" }
-  unique_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
+  bool __attribute__((unused)) test = true;
+
+  future<int> p1;
+  VERIFY( !p1.valid() );
+  future<int&> p2;
+  VERIFY( !p2.valid() );
+  future<void> p3;
+  VERIFY( !p3.valid() );
+  future<ClassType> p4;
+  VERIFY( !p4.valid() );
+  future<AbstractClass&> p5;
+  VERIFY( !p5.valid() );
 }
 
 int main()
@@ -42,4 +49,3 @@ int main()
   test01();
   return 0;
 }
-// { dg-excess-errors "note" }
index 17eaa91..2649314 100644 (file)
@@ -30,8 +30,8 @@ void test01()
 {
   // move
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
-  std::unique_future<int> f2(std::move(f1));
+  std::future<int> f1(p1.get_future());
+  std::future<int> f2(std::move(f1));
 }
 
 int main()
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/move_assign.cc
new file mode 100644 (file)
index 0000000..3208cf8
--- /dev/null
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+std::future<int> get() { return std::promise<int>().get_future(); }
+
+void test01()
+{
+  // assign
+  std::future<int> p1;
+  std::future<int> p2 = get();
+  p1 = std::move(p2);
+  VERIFY( p1.valid() );
+  VERIFY( !p2.valid() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 5c9a454..a0e4a43 100644 (file)
@@ -34,10 +34,11 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::future<int> f1(p1.get_future());
 
   p1.set_value(value);
   VERIFY( f1.get() == value );
+  VERIFY( !f1.valid() );
 }
 
 void test02()
@@ -45,19 +46,21 @@ void test02()
   bool test __attribute__((unused)) = true;
 
   std::promise<int&> p1;
-  std::unique_future<int&> f1(p1.get_future());
+  std::future<int&> f1(p1.get_future());
 
   p1.set_value(value);
   VERIFY( &f1.get() == &value );
+  VERIFY( !f1.valid() );
 }
 
 void test03()
 {
   std::promise<void> p1;
-  std::unique_future<void> f1(p1.get_future());
+  std::future<void> f1(p1.get_future());
 
   p1.set_value();
   f1.get();
+  VERIFY( !f1.valid() );
 }
 
 int main()
index e6317fe..22ca15c 100644 (file)
@@ -35,7 +35,7 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::future<int> f1(p1.get_future());
 
   p1.set_exception(std::copy_exception(value));
   try
@@ -47,6 +47,7 @@ void test01()
   {
     VERIFY( e == value );
   }
+  VERIFY( !f1.valid() );
 }
 
 void test02()
@@ -54,7 +55,7 @@ void test02()
   bool test __attribute__((unused)) = true;
 
   std::promise<int&> p1;
-  std::unique_future<int&> f1(p1.get_future());
+  std::future<int&> f1(p1.get_future());
 
   p1.set_exception(std::copy_exception(value));
   try
@@ -66,6 +67,7 @@ void test02()
   {
     VERIFY( e == value );
   }
+  VERIFY( !f1.valid() );
 }
 
 void test03()
@@ -73,7 +75,7 @@ void test03()
   bool test __attribute__((unused)) = true;
 
   std::promise<void> p1;
-  std::unique_future<void> f1(p1.get_future());
+  std::future<void> f1(p1.get_future());
 
   p1.set_exception(std::copy_exception(value));
   try
@@ -85,6 +87,7 @@ void test03()
   {
     VERIFY( e == value );
   }
+  VERIFY( !f1.valid() );
 }
 
 int main()
@@ -6,7 +6,7 @@
 // { dg-require-gthreads "" }
 // { dg-require-atomic-builtins "" }
 
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2010 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -31,17 +31,22 @@ void test01()
 {
   bool test __attribute__((unused)) = true;
 
+  std::future<int> f0;
+  VERIFY( !f0.valid() );
+
   std::promise<int> p1;
-  std::shared_future<int> f1(p1.get_future());
-  std::shared_future<int> f2(f1);
+  std::future<int> f1(p1.get_future());
 
-  VERIFY( !f1.is_ready() );
-  VERIFY( !f2.is_ready() );
+  VERIFY( f1.valid() );
 
   p1.set_value(1);
 
-  VERIFY( f1.is_ready() );
-  VERIFY( f2.is_ready() );
+  VERIFY( f1.valid() );
+
+  f1 = std::move(f0);
+
+  VERIFY( !f1.valid() );
+  VERIFY( !f0.valid() );
 }
 
 int main()
index b9c9402..94a431f 100644 (file)
@@ -31,7 +31,7 @@
 #include <testsuite_hooks.h>
 
 
-void wait(std::unique_future<void>& f)
+void wait(std::future<void>& f)
 {
   f.wait();
 }
@@ -39,7 +39,7 @@ void wait(std::unique_future<void>& f)
 void test01()
 {
   std::promise<void> p1;
-  std::unique_future<void> f1(p1.get_future());
+  std::future<void> f1(p1.get_future());
 
   std::thread t1(wait, std::ref(f1));
 
index 0652400..0123caa 100644 (file)
@@ -33,7 +33,7 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::future<int> f1(p1.get_future());
 
   std::chrono::milliseconds delay(100);
 
index 55bdcbc..bea1e0e 100644 (file)
@@ -38,7 +38,7 @@ void test01()
   bool test __attribute__((unused)) = true;
 
   std::promise<int> p1;
-  std::unique_future<int> f1(p1.get_future());
+  std::future<int> f1(p1.get_future());
 
   auto when = make_time(10);
   VERIFY( !f1.wait_until(when) );
index 01e5c59..5d761b1 100644 (file)
@@ -26,9 +26,9 @@
 #include <testsuite_tr1.h>
 
 using namespace __gnu_test;
-using std::unique_future;
-template class unique_future<int>;
-template class unique_future<int&>;
-template class unique_future<void>;
-template class unique_future<ClassType>;
-template class unique_future<ClassType&>;
+using std::future;
+template class future<int>;
+template class future<int&>;
+template class future<void>;
+template class future<ClassType>;
+template class future<ClassType&>;