aboutsummaryrefslogtreecommitdiff
path: root/test/std/thread/futures/futures.unique_future
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/futures/futures.unique_future')
-rw-r--r--test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp74
-rw-r--r--test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp66
-rw-r--r--test/std/thread/futures/futures.unique_future/default.pass.cpp35
-rw-r--r--test/std/thread/futures/futures.unique_future/dtor.pass.cpp68
-rw-r--r--test/std/thread/futures/futures.unique_future/get.pass.cpp145
-rw-r--r--test/std/thread/futures/futures.unique_future/move_assign.pass.cpp76
-rw-r--r--test/std/thread/futures/futures.unique_future/move_ctor.pass.cpp70
-rw-r--r--test/std/thread/futures/futures.unique_future/share.pass.cpp68
-rw-r--r--test/std/thread/futures/futures.unique_future/wait.pass.cpp88
-rw-r--r--test/std/thread/futures/futures.unique_future/wait_for.pass.cpp97
-rw-r--r--test/std/thread/futures/futures.unique_future/wait_until.pass.cpp129
11 files changed, 916 insertions, 0 deletions
diff --git a/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp b/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp
new file mode 100644
index 000000000000..ebdcbf98d996
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class future<R>
+
+// future& operator=(const future&) = delete;
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp b/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp
new file mode 100644
index 000000000000..8d43294edc26
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class future<R>
+
+// future(const future&) = delete;
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::future<T> f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = f0;
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::future<T> f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/default.pass.cpp b/test/std/thread/futures/futures.unique_future/default.pass.cpp
new file mode 100644
index 000000000000..84cb84650dcd
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/default.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// future();
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ std::future<int> f;
+ assert(!f.valid());
+ }
+ {
+ std::future<int&> f;
+ assert(!f.valid());
+ }
+ {
+ std::future<void> f;
+ assert(!f.valid());
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/dtor.pass.cpp b/test/std/thread/futures/futures.unique_future/dtor.pass.cpp
new file mode 100644
index 000000000000..5e9697bb939b
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/dtor.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// ~future();
+
+#include <future>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+int main()
+{
+ assert(test_alloc_base::count == 0);
+ {
+ typedef int T;
+ std::future<T> f;
+ {
+ std::promise<T> p(std::allocator_arg, test_allocator<T>());
+ assert(test_alloc_base::count == 1);
+ f = p.get_future();
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 0);
+ {
+ typedef int& T;
+ std::future<T> f;
+ {
+ std::promise<T> p(std::allocator_arg, test_allocator<int>());
+ assert(test_alloc_base::count == 1);
+ f = p.get_future();
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 0);
+ {
+ typedef void T;
+ std::future<T> f;
+ {
+ std::promise<T> p(std::allocator_arg, test_allocator<T>());
+ assert(test_alloc_base::count == 1);
+ f = p.get_future();
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 1);
+ assert(f.valid());
+ }
+ assert(test_alloc_base::count == 0);
+}
diff --git a/test/std/thread/futures/futures.unique_future/get.pass.cpp b/test/std/thread/futures/futures.unique_future/get.pass.cpp
new file mode 100644
index 000000000000..758e38a7dae9
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/get.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// R future::get();
+// R& future<R&>::get();
+// void future<void>::get();
+
+#include <future>
+#include <cassert>
+
+void func1(std::promise<int> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_value(3);
+}
+
+void func2(std::promise<int> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_exception(std::make_exception_ptr(3));
+}
+
+int j = 0;
+
+void func3(std::promise<int&> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ j = 5;
+ p.set_value(j);
+}
+
+void func4(std::promise<int&> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_exception(std::make_exception_ptr(3.5));
+}
+
+void func5(std::promise<void> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_value();
+}
+
+void func6(std::promise<void> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_exception(std::make_exception_ptr('c'));
+}
+
+int main()
+{
+ {
+ typedef int T;
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.get() == 3);
+ assert(!f.valid());
+ }
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func2, std::move(p)).detach();
+ try
+ {
+ assert(f.valid());
+ assert(f.get() == 3);
+ assert(false);
+ }
+ catch (int i)
+ {
+ assert(i == 3);
+ }
+ assert(!f.valid());
+ }
+ }
+ {
+ typedef int& T;
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.get() == 5);
+ assert(!f.valid());
+ }
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func4, std::move(p)).detach();
+ try
+ {
+ assert(f.valid());
+ assert(f.get() == 3);
+ assert(false);
+ }
+ catch (double i)
+ {
+ assert(i == 3.5);
+ }
+ assert(!f.valid());
+ }
+ }
+ {
+ typedef void T;
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ f.get();
+ assert(!f.valid());
+ }
+ {
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func6, std::move(p)).detach();
+ try
+ {
+ assert(f.valid());
+ f.get();
+ assert(false);
+ }
+ catch (char i)
+ {
+ assert(i == 'c');
+ }
+ assert(!f.valid());
+ }
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/move_assign.pass.cpp b/test/std/thread/futures/futures.unique_future/move_assign.pass.cpp
new file mode 100644
index 000000000000..8d38b81f0cda
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/move_assign.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// future& operator=(future&& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/thread/futures/futures.unique_future/move_ctor.pass.cpp b/test/std/thread/futures/futures.unique_future/move_ctor.pass.cpp
new file mode 100644
index 000000000000..e12c920886fa
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/move_ctor.pass.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// future(future&& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/thread/futures/futures.unique_future/share.pass.cpp b/test/std/thread/futures/futures.unique_future/share.pass.cpp
new file mode 100644
index 000000000000..794b5ce38feb
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/share.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// shared_future<R> share() &&;
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::shared_future<T> f = std::move(f0.share());
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/wait.pass.cpp b/test/std/thread/futures/futures.unique_future/wait.pass.cpp
new file mode 100644
index 000000000000..e10d37cf8064
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/wait.pass.cpp
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// void wait() const;
+
+#include <future>
+#include <cassert>
+
+void func1(std::promise<int> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_value(3);
+}
+
+int j = 0;
+
+void func3(std::promise<int&> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ j = 5;
+ p.set_value(j);
+}
+
+void func5(std::promise<void> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.set_value();
+}
+
+int main()
+{
+ typedef std::chrono::high_resolution_clock Clock;
+ typedef std::chrono::duration<double, std::milli> ms;
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ f.wait();
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ f.wait();
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ f.wait();
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp b/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
new file mode 100644
index 000000000000..0a381d9ca2f0
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <future>
+
+// class future<R>
+
+// template <class Rep, class Period>
+// future_status
+// wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+
+#include <future>
+#include <cassert>
+
+typedef std::chrono::milliseconds ms;
+
+void func1(std::promise<int> p)
+{
+ std::this_thread::sleep_for(ms(500));
+ p.set_value(3);
+}
+
+int j = 0;
+
+void func3(std::promise<int&> p)
+{
+ std::this_thread::sleep_for(ms(500));
+ j = 5;
+ p.set_value(j);
+}
+
+void func5(std::promise<void> p)
+{
+ std::this_thread::sleep_for(ms(500));
+ p.set_value();
+}
+
+int main()
+{
+ typedef std::chrono::high_resolution_clock Clock;
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(50));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(50));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_for(ms(300)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(50));
+ }
+}
diff --git a/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp b/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
new file mode 100644
index 000000000000..d5865b9b9dcf
--- /dev/null
+++ b/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
@@ -0,0 +1,129 @@
+ //===----------------------------------------------------------------------===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file is dual licensed under the MIT and the University of Illinois Open
+ // Source Licenses. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // UNSUPPORTED: libcpp-has-no-threads
+
+ // <future>
+
+ // class future<R>
+
+ // template <class Clock, class Duration>
+ // future_status
+ // wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+
+ #include <future>
+ #include <atomic>
+ #include <cassert>
+
+ enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
+ typedef std::chrono::milliseconds ms;
+
+ std::atomic<WorkerThreadState> thread_state(WorkerThreadState::Uninitialized);
+
+ void set_worker_thread_state(WorkerThreadState state)
+ {
+ thread_state.store(state, std::memory_order_relaxed);
+ }
+
+ void wait_for_worker_thread_state(WorkerThreadState state)
+ {
+ while (thread_state.load(std::memory_order_relaxed) != state);
+ }
+
+ void func1(std::promise<int> p)
+ {
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ p.set_value(3);
+ set_worker_thread_state(WorkerThreadState::Exiting);
+ }
+
+ int j = 0;
+
+ void func3(std::promise<int&> p)
+ {
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ j = 5;
+ p.set_value(j);
+ set_worker_thread_state(WorkerThreadState::Exiting);
+ }
+
+ void func5(std::promise<void> p)
+ {
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ p.set_value();
+ set_worker_thread_state(WorkerThreadState::Exiting);
+ }
+
+ int main()
+ {
+ typedef std::chrono::high_resolution_clock Clock;
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ }