summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2010-09-03 18:39:25 +0000
committerHoward Hinnant <hhinnant@apple.com>2010-09-03 18:39:25 +0000
commitead85506a763516f78f3671cde20c22fb7143312 (patch)
treed1025205884fef58ba745b9c2b0032bdaf80ff76 /libcxx/test
parent03f4be86ba780e890a974da7cd5511491c3e6eac (diff)
downloadbcm5719-llvm-ead85506a763516f78f3671cde20c22fb7143312.tar.gz
bcm5719-llvm-ead85506a763516f78f3671cde20c22fb7143312.zip
[futures.shared_future]
llvm-svn: 112990
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/copy_assign.pass.cpp74
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/copy_ctor.pass.cpp66
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/ctor_future.pass.cpp66
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/default.pass.cpp33
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/dtor.pass.cpp66
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/get.pass.cpp143
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/move_assign.pass.cpp74
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/move_ctor.pass.cpp66
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/wait.pass.cpp86
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/wait_for.pass.cpp95
-rw-r--r--libcxx/test/thread/futures/futures.shared_future/wait_until.pass.cpp95
11 files changed, 864 insertions, 0 deletions
diff --git a/libcxx/test/thread/futures/futures.shared_future/copy_assign.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/copy_assign.pass.cpp
new file mode 100644
index 00000000000..04dc1f86724
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/copy_assign.pass.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future& operator=(const shared_future& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+#endif // _LIBCPP_MOVE
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/copy_ctor.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/copy_ctor.pass.cpp
new file mode 100644
index 00000000000..ec17da04256
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/copy_ctor.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future(const shared_future& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = f0;
+ assert(f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = f0;
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/ctor_future.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/ctor_future.pass.cpp
new file mode 100644
index 00000000000..2fb83ff7878
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/ctor_future.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future(future<R>&& rhs);
+
+#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);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::future<T> f0;
+ std::shared_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::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::future<T> f0;
+ std::shared_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::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::future<T> f0;
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/default.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/default.pass.cpp
new file mode 100644
index 00000000000..07ec85a0ce7
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/default.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future();
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ std::shared_future<int> f;
+ assert(!f.valid());
+ }
+ {
+ std::shared_future<int&> f;
+ assert(!f.valid());
+ }
+ {
+ std::shared_future<void> f;
+ assert(!f.valid());
+ }
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/dtor.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/dtor.pass.cpp
new file mode 100644
index 00000000000..d773a80a23c
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/dtor.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// ~shared_future();
+
+#include <future>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+int main()
+{
+ assert(test_alloc_base::count == 0);
+ {
+ typedef int T;
+ std::shared_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::shared_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::shared_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/libcxx/test/thread/futures/futures.shared_future/get.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/get.pass.cpp
new file mode 100644
index 00000000000..d3445134599
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/get.pass.cpp
@@ -0,0 +1,143 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// const R& shared_future::get();
+// R& shared_future<R&>::get();
+// void shared_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::shared_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::shared_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::shared_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::shared_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::shared_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::shared_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/libcxx/test/thread/futures/futures.shared_future/move_assign.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/move_assign.pass.cpp
new file mode 100644
index 00000000000..496bac5ae5e
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/move_assign.pass.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future& operator=(shared_future&& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f;
+ f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+#endif // _LIBCPP_MOVE
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/move_ctor.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/move_ctor.pass.cpp
new file mode 100644
index 00000000000..2130071c75c
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/move_ctor.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// shared_future(shared_future&& rhs);
+
+#include <future>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef int& T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_future<T> f0 = p.get_future();
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(f.valid());
+ }
+ {
+ typedef void T;
+ std::shared_future<T> f0;
+ std::shared_future<T> f = std::move(f0);
+ assert(!f0.valid());
+ assert(!f.valid());
+ }
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/wait.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/wait.pass.cpp
new file mode 100644
index 00000000000..1bcafb14c24
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/wait.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_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::shared_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::shared_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::shared_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/libcxx/test/thread/futures/futures.shared_future/wait_for.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/wait_for.pass.cpp
new file mode 100644
index 00000000000..bb3bb79f490
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/wait_for.pass.cpp
@@ -0,0 +1,95 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_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::shared_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(5));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_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(5));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_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(5));
+ }
+}
diff --git a/libcxx/test/thread/futures/futures.shared_future/wait_until.pass.cpp b/libcxx/test/thread/futures/futures.shared_future/wait_until.pass.cpp
new file mode 100644
index 00000000000..aac0ff2d46a
--- /dev/null
+++ b/libcxx/test/thread/futures/futures.shared_future/wait_until.pass.cpp
@@ -0,0 +1,95 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <future>
+
+// class shared_future<R>
+
+// template <class Clock, class Duration>
+// future_status
+// wait_until(const chrono::time_point<Clock, Duration>& abs_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::shared_future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + 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(5));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::shared_future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + 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(5));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::shared_future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(300)) == std::future_status::timeout);
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + 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(5));
+ }
+}
OpenPOWER on IntegriCloud