Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
198
test/std/thread/futures/futures.async/async.pass.cpp
Normal file
198
test/std/thread/futures/futures.async/async.pass.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// template <class F, class... Args>
|
||||
// future<typename result_of<F(Args...)>::type>
|
||||
// async(F&& f, Args&&... args);
|
||||
|
||||
// template <class F, class... Args>
|
||||
// future<typename result_of<F(Args...)>::type>
|
||||
// async(launch policy, F&& f, Args&&... args);
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
typedef std::chrono::high_resolution_clock Clock;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
|
||||
int f0()
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
return 3;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
int& f1()
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
return i;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
}
|
||||
|
||||
std::unique_ptr<int> f3(int i)
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
return std::unique_ptr<int>(new int(i));
|
||||
}
|
||||
|
||||
std::unique_ptr<int> f4(std::unique_ptr<int>&& p)
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
return std::move(p);
|
||||
}
|
||||
|
||||
void f5(int i)
|
||||
{
|
||||
std::this_thread::sleep_for(ms(200));
|
||||
throw i;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::future<int> f = std::async(f0);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int> f = std::async(std::launch::async, f0);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int> f = std::async(std::launch::any, f0);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int> f = std::async(std::launch::deferred, f0);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
std::future<int&> f = std::async(f1);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int&> f = std::async(std::launch::async, f1);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int&> f = std::async(std::launch::any, f1);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<int&> f = std::async(std::launch::deferred, f1);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
std::future<void> f = std::async(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<void> f = std::async(std::launch::async, f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<void> f = std::async(std::launch::any, f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
{
|
||||
std::future<void> f = std::async(std::launch::deferred, f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
std::future<std::unique_ptr<int>> f = std::async(f3, 3);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(*f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
std::future<std::unique_ptr<int>> f =
|
||||
std::async(f4, std::unique_ptr<int>(new int(3)));
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
assert(*f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 < ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
std::future<void> f = std::async(f5, 3);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
try { f.get(); assert (false); } catch ( int ex ) {}
|
||||
}
|
||||
|
||||
{
|
||||
std::future<void> f = std::async(std::launch::deferred, f5, 3);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
try { f.get(); assert (false); } catch ( int ex ) {}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual error_condition default_error_condition(int ev) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
std::error_condition e_cond = e_cat.default_error_condition(static_cast<int>(std::errc::not_a_directory));
|
||||
assert(e_cond.category() == e_cat);
|
||||
assert(e_cond.value() == static_cast<int>(std::errc::not_a_directory));
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual bool equivalent(const error_code& code, int condition) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
assert(e_cat.equivalent(std::error_code(5, e_cat), 5));
|
||||
assert(!e_cat.equivalent(std::error_code(5, e_cat), 6));
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual bool equivalent(int code, const error_condition& condition) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
std::error_condition e_cond = e_cat.default_error_condition(5);
|
||||
assert(e_cat.equivalent(5, e_cond));
|
||||
assert(!e_cat.equivalent(6, e_cond));
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
#include <future>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& ec = std::future_category();
|
||||
assert(std::strcmp(ec.name(), "future") == 0);
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 error_code
|
||||
|
||||
// error_code make_error_code(future_errc e);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::error_code ec = make_error_code(std::future_errc::broken_promise);
|
||||
assert(ec.value() == static_cast<int>(std::future_errc::broken_promise));
|
||||
assert(ec.category() == std::future_category());
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 error_condition
|
||||
|
||||
// error_condition make_error_condition(future_errc e);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::error_condition ec1 =
|
||||
std::make_error_condition(std::future_errc::future_already_retrieved);
|
||||
assert(ec1.value() ==
|
||||
static_cast<int>(std::future_errc::future_already_retrieved));
|
||||
assert(ec1.category() == std::future_category());
|
||||
}
|
||||
}
|
43
test/std/thread/futures/futures.future_error/code.pass.cpp
Normal file
43
test/std/thread/futures/futures.future_error/code.pass.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_error
|
||||
|
||||
// const error_code& code() const throw();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::broken_promise);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::future_already_retrieved);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::promise_already_satisfied);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::no_state);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
}
|
23
test/std/thread/futures/futures.future_error/types.pass.cpp
Normal file
23
test/std/thread/futures/futures.future_error/types.pass.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_error : public logic_error {...};
|
||||
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_convertible<std::future_error*,
|
||||
std::logic_error*>::value), "");
|
||||
}
|
50
test/std/thread/futures/futures.future_error/what.pass.cpp
Normal file
50
test/std/thread/futures/futures.future_error/what.pass.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// LWG 2056 changed the values of future_errc, so if we're using new headers
|
||||
// with an old library we'll get incorrect messages.
|
||||
//
|
||||
// XFAIL: with_system_lib=x86_64-apple-darwin11
|
||||
// XFAIL: with_system_lib=x86_64-apple-darwin12
|
||||
// XFAIL: with_system_lib=x86_64-apple-darwin13
|
||||
|
||||
// <future>
|
||||
|
||||
// class future_error
|
||||
|
||||
// const char* what() const throw();
|
||||
|
||||
#include <future>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::broken_promise));
|
||||
assert(std::strcmp(f.what(), "The associated promise has been destructed prior "
|
||||
"to the associated state becoming ready.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::future_already_retrieved));
|
||||
assert(std::strcmp(f.what(), "The future has already been retrieved from "
|
||||
"the promise or packaged_task.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::promise_already_satisfied));
|
||||
assert(std::strcmp(f.what(), "The state of the promise has already been set.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::no_state));
|
||||
assert(std::strcmp(f.what(), "Operation not permitted on an object without "
|
||||
"an associated state.") == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class future_errc
|
||||
// {
|
||||
// future_already_retrieved = 1,
|
||||
// promise_already_satisfied,
|
||||
// no_state
|
||||
// broken_promise,
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(static_cast<int>(std::future_errc::future_already_retrieved) == 1, "");
|
||||
static_assert(static_cast<int>(std::future_errc::promise_already_satisfied) == 2, "");
|
||||
static_assert(static_cast<int>(std::future_errc::no_state) == 3, "");
|
||||
static_assert(static_cast<int>(std::future_errc::broken_promise) == 4, "");
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class future_status
|
||||
// {
|
||||
// ready,
|
||||
// timeout,
|
||||
// deferred
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(static_cast<int>(std::future_status::ready) == 0, "");
|
||||
static_assert(static_cast<int>(std::future_status::timeout) == 1, "");
|
||||
static_assert(static_cast<int>(std::future_status::deferred) == 2, "");
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// template <> struct is_error_code_enum<future_errc> : public true_type {};
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::is_error_code_enum<std::future_errc>::value, "");
|
||||
}
|
45
test/std/thread/futures/futures.overview/launch.pass.cpp
Normal file
45
test/std/thread/futures/futures.overview/launch.pass.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class launch
|
||||
// {
|
||||
// async = 1,
|
||||
// deferred = 2,
|
||||
// any = async | deferred
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
||||
static_assert(static_cast<int>(std::launch::any) ==
|
||||
(static_cast<int>(std::launch::async) | static_cast<int>(std::launch::deferred)), "");
|
||||
#else
|
||||
static_assert(std::launch::any == (std::launch::async | std::launch::deferred), "");
|
||||
static_assert(std::launch(0) == (std::launch::async & std::launch::deferred), "");
|
||||
static_assert(std::launch::any == (std::launch::async ^ std::launch::deferred), "");
|
||||
static_assert(std::launch::deferred == ~std::launch::async, "");
|
||||
std::launch x = std::launch::async;
|
||||
x &= std::launch::deferred;
|
||||
assert(x == std::launch(0));
|
||||
x = std::launch::async;
|
||||
x |= std::launch::deferred;
|
||||
assert(x == std::launch::any);
|
||||
x ^= std::launch::deferred;
|
||||
assert(x == std::launch::async);
|
||||
#endif
|
||||
static_assert(static_cast<int>(std::launch::async) == 1, "");
|
||||
static_assert(static_cast<int>(std::launch::deferred) == 2, "");
|
||||
}
|
84
test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp
Normal file
84
test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// template <class Allocator>
|
||||
// promise(allocator_arg_t, const Allocator& a);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int&> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<void> p(std::allocator_arg, test_allocator<void>());
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<void> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
// Test with a minimal allocator
|
||||
{
|
||||
std::promise<int> p(std::allocator_arg, bare_allocator<void>());
|
||||
std::future<int> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<int&> p(std::allocator_arg, bare_allocator<void>());
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<void> p(std::allocator_arg, bare_allocator<void>());
|
||||
std::future<void> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
// Test with a minimal allocator that returns class-type pointers
|
||||
{
|
||||
std::promise<int> p(std::allocator_arg, min_allocator<void>());
|
||||
std::future<int> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<int&> p(std::allocator_arg, min_allocator<void>());
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<void> p(std::allocator_arg, min_allocator<void>());
|
||||
std::future<void> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
}
|
87
test/std/thread/futures/futures.promise/copy_assign.fail.cpp
Normal file
87
test/std/thread/futures/futures.promise/copy_assign.fail.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// promise& operator=(const promise& rhs) = delete;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = p0;
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int&> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = p0;
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<void> p0(std::allocator_arg, test_allocator<void>());
|
||||
std::promise<void> p(std::allocator_arg, test_allocator<void>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = p0;
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<void> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
}
|
81
test/std/thread/futures/futures.promise/copy_ctor.fail.cpp
Normal file
81
test/std/thread/futures/futures.promise/copy_ctor.fail.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// promise(const promise&) = delete;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int&> p(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<void> p0(std::allocator_arg, test_allocator<void>());
|
||||
std::promise<void> p(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<void> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
}
|
38
test/std/thread/futures/futures.promise/default.pass.cpp
Normal file
38
test/std/thread/futures/futures.promise/default.pass.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// promise();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::promise<int> p;
|
||||
std::future<int> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<int&> p;
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
{
|
||||
std::promise<void> p;
|
||||
std::future<void> f = p.get_future();
|
||||
assert(f.valid());
|
||||
}
|
||||
}
|
116
test/std/thread/futures/futures.promise/dtor.pass.cpp
Normal file
116
test/std/thread/futures/futures.promise/dtor.pass.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// ~promise();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef int T;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value(3);
|
||||
}
|
||||
assert(f.get() == 3);
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
T i = f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
typedef int& T;
|
||||
int i = 4;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value(i);
|
||||
}
|
||||
assert(&f.get() == &i);
|
||||
}
|
||||
{
|
||||
typedef int& T;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
T i = f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
typedef void T;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value();
|
||||
}
|
||||
f.get();
|
||||
assert(true);
|
||||
}
|
||||
{
|
||||
typedef void T;
|
||||
std::future<T> f;
|
||||
{
|
||||
std::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
// LWG 2056 changed the values of future_errc, so if we're using new
|
||||
// headers with an old library the error codes won't line up.
|
||||
//
|
||||
// Note that this particular check only applies to promise<void>
|
||||
// since the other specializations happen to be implemented in the
|
||||
// header rather than the library.
|
||||
assert(
|
||||
e.code() == make_error_code(std::future_errc::broken_promise) ||
|
||||
e.code() == std::error_code(0, std::future_category()));
|
||||
}
|
||||
}
|
||||
}
|
55
test/std/thread/futures/futures.promise/get_future.pass.cpp
Normal file
55
test/std/thread/futures/futures.promise/get_future.pass.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// future<R> get_future();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::promise<double> p;
|
||||
std::future<double> f = p.get_future();
|
||||
p.set_value(105.5);
|
||||
assert(f.get() == 105.5);
|
||||
}
|
||||
{
|
||||
std::promise<double> p;
|
||||
std::future<double> f = p.get_future();
|
||||
try
|
||||
{
|
||||
f = p.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::future_already_retrieved));
|
||||
}
|
||||
}
|
||||
{
|
||||
std::promise<double> p;
|
||||
std::promise<double> p0 = std::move(p);
|
||||
try
|
||||
{
|
||||
std::future<double> f = p.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
}
|
91
test/std/thread/futures/futures.promise/move_assign.pass.cpp
Normal file
91
test/std/thread/futures/futures.promise/move_assign.pass.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// promise& operator=(promise&& rhs);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = std::move(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int&> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = std::move(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<void> p0(std::allocator_arg, test_allocator<void>());
|
||||
std::promise<void> p(std::allocator_arg, test_allocator<void>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p = std::move(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<void> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
85
test/std/thread/futures/futures.promise/move_ctor.pass.cpp
Normal file
85
test/std/thread/futures/futures.promise/move_ctor.pass.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// promise(promise&& rhs);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(std::move(p0));
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int&> p(std::move(p0));
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int&> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<void> p0(std::allocator_arg, test_allocator<void>());
|
||||
std::promise<void> p(std::move(p0));
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<void> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void set_exception(exception_ptr p);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef int T;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
p.set_exception(std::make_exception_ptr(3));
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 3);
|
||||
}
|
||||
try
|
||||
{
|
||||
p.set_exception(std::make_exception_ptr(3));
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise::set_exception_at_thread_exit(exception_ptr p);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
void func(std::promise<int> p)
|
||||
{
|
||||
const int i = 5;
|
||||
p.set_exception_at_thread_exit(std::make_exception_ptr(3));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef int T;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 3);
|
||||
}
|
||||
}
|
||||
}
|
43
test/std/thread/futures/futures.promise/set_lvalue.pass.cpp
Normal file
43
test/std/thread/futures/futures.promise/set_lvalue.pass.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise<R&>::set_value(R& r);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef int& T;
|
||||
int i = 3;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
p.set_value(i);
|
||||
int& j = f.get();
|
||||
assert(j == 3);
|
||||
++i;
|
||||
assert(j == 4);
|
||||
try
|
||||
{
|
||||
p.set_value(i);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise<R&>::set_value_at_thread_exit(R& r);
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int i = 0;
|
||||
|
||||
void func(std::promise<int&> p)
|
||||
{
|
||||
p.set_value_at_thread_exit(i);
|
||||
i = 4;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::promise<int&> p;
|
||||
std::future<int&> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
assert(f.get() == 4);
|
||||
}
|
||||
}
|
69
test/std/thread/futures/futures.promise/set_rvalue.pass.cpp
Normal file
69
test/std/thread/futures/futures.promise/set_rvalue.pass.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise::set_value(R&& r);
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
A(const A&) = delete;
|
||||
A(A&&) {throw 9;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
{
|
||||
typedef std::unique_ptr<int> T;
|
||||
T i(new int(3));
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
p.set_value(std::move(i));
|
||||
assert(*f.get() == 3);
|
||||
try
|
||||
{
|
||||
p.set_value(std::move(i));
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
{
|
||||
typedef A T;
|
||||
T i;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
try
|
||||
{
|
||||
p.set_value(std::move(i));
|
||||
assert(false);
|
||||
}
|
||||
catch (int j)
|
||||
{
|
||||
assert(j == 9);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise::set_value_at_thread_exit(R&& r);
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
void func(std::promise<std::unique_ptr<int>> p)
|
||||
{
|
||||
p.set_value_at_thread_exit(std::unique_ptr<int>(new int(5)));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
{
|
||||
std::promise<std::unique_ptr<int>> p;
|
||||
std::future<std::unique_ptr<int>> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
assert(*f.get() == 5);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -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 promise<R>
|
||||
|
||||
// void promise::set_value_at_thread_exit(const R& r);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
void func(std::promise<int> p)
|
||||
{
|
||||
const int i = 5;
|
||||
p.set_value_at_thread_exit(i);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::promise<int> p;
|
||||
std::future<int> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
assert(f.get() == 5);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise<void>::set_value_at_thread_exit();
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int i = 0;
|
||||
|
||||
void func(std::promise<void> p)
|
||||
{
|
||||
p.set_value_at_thread_exit();
|
||||
i = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::promise<void> p;
|
||||
std::future<void> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
f.get();
|
||||
assert(i == 1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise::set_value(const R& r);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
A(const A&) {throw 10;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef int T;
|
||||
T i = 3;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
p.set_value(i);
|
||||
++i;
|
||||
assert(f.get() == 3);
|
||||
--i;
|
||||
try
|
||||
{
|
||||
p.set_value(i);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
{
|
||||
typedef A T;
|
||||
T i;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
try
|
||||
{
|
||||
p.set_value(i);
|
||||
assert(false);
|
||||
}
|
||||
catch (int j)
|
||||
{
|
||||
assert(j == 10);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void promise<void>::set_value();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef void T;
|
||||
std::promise<T> p;
|
||||
std::future<T> f = p.get_future();
|
||||
p.set_value();
|
||||
f.get();
|
||||
try
|
||||
{
|
||||
p.set_value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
}
|
84
test/std/thread/futures/futures.promise/swap.pass.cpp
Normal file
84
test/std/thread/futures/futures.promise/swap.pass.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// void swap(promise& other);
|
||||
|
||||
// template <class R> void swap(promise<R>& x, promise<R>& y);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
p.swap(p0);
|
||||
assert(test_alloc_base::count == 2);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 2);
|
||||
assert(f.valid());
|
||||
f = p0.get_future();
|
||||
assert(f.valid());
|
||||
assert(test_alloc_base::count == 2);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p(std::allocator_arg, test_allocator<int>());
|
||||
assert(test_alloc_base::count == 2);
|
||||
swap(p, p0);
|
||||
assert(test_alloc_base::count == 2);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 2);
|
||||
assert(f.valid());
|
||||
f = p0.get_future();
|
||||
assert(f.valid());
|
||||
assert(test_alloc_base::count == 2);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p;
|
||||
assert(test_alloc_base::count == 1);
|
||||
p.swap(p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
f = p0.get_future();
|
||||
assert(f.valid());
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
{
|
||||
std::promise<int> p0(std::allocator_arg, test_allocator<int>());
|
||||
std::promise<int> p;
|
||||
assert(test_alloc_base::count == 1);
|
||||
swap(p, p0);
|
||||
assert(test_alloc_base::count == 1);
|
||||
std::future<int> f = p.get_future();
|
||||
assert(test_alloc_base::count == 1);
|
||||
assert(f.valid());
|
||||
f = p0.get_future();
|
||||
assert(f.valid());
|
||||
assert(test_alloc_base::count == 1);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 promise<R>
|
||||
|
||||
// template <class R, class Alloc>
|
||||
// struct uses_allocator<promise<R>, Alloc>
|
||||
// : true_type { };
|
||||
|
||||
#include <future>
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::uses_allocator<std::promise<int>, test_allocator<int> >::value), "");
|
||||
static_assert((std::uses_allocator<std::promise<int&>, test_allocator<int> >::value), "");
|
||||
static_assert((std::uses_allocator<std::promise<void>, test_allocator<void> >::value), "");
|
||||
}
|
@@ -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 shared_future<R>
|
||||
|
||||
// shared_future& operator=(const shared_future& rhs);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
{
|
||||
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_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -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 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());
|
||||
}
|
||||
}
|
@@ -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 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());
|
||||
}
|
||||
}
|
@@ -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 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());
|
||||
}
|
||||
}
|
68
test/std/thread/futures/futures.shared_future/dtor.pass.cpp
Normal file
68
test/std/thread/futures/futures.shared_future/dtor.pass.cpp
Normal file
@@ -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 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);
|
||||
}
|
145
test/std/thread/futures/futures.shared_future/get.pass.cpp
Normal file
145
test/std/thread/futures/futures.shared_future/get.pass.cpp
Normal file
@@ -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 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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 shared_future<R>
|
||||
|
||||
// shared_future& operator=(shared_future&& rhs);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
{
|
||||
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_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -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 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());
|
||||
}
|
||||
}
|
88
test/std/thread/futures/futures.shared_future/wait.pass.cpp
Normal file
88
test/std/thread/futures/futures.shared_future/wait.pass.cpp
Normal file
@@ -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 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));
|
||||
}
|
||||
}
|
@@ -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 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));
|
||||
}
|
||||
}
|
@@ -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 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));
|
||||
}
|
||||
}
|
13
test/std/thread/futures/futures.state/nothing_to_do.pass.cpp
Normal file
13
test/std/thread/futures/futures.state/nothing_to_do.pass.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// packaged_task& operator=(packaged_task&) = delete;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p = p0;
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p = p0;
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// packaged_task& operator=(packaged_task&& other);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p = std::move(p0);
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p = std::move(p0);
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
// template <class F>
|
||||
// packaged_task(F&& f);
|
||||
// These constructors shall not participate in overload resolution if
|
||||
// decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
struct A {};
|
||||
typedef std::packaged_task<A(int, char)> PT;
|
||||
typedef volatile std::packaged_task<A(int, char)> VPT;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
PT p { VPT{} };
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
// template <class F, class Allocator>
|
||||
// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
|
||||
// These constructors shall not participate in overload resolution if
|
||||
// decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../test_allocator.h"
|
||||
|
||||
struct A {};
|
||||
typedef std::packaged_task<A(int, char)> PT;
|
||||
typedef volatile std::packaged_task<A(int, char)> VPT;
|
||||
|
||||
int main()
|
||||
{
|
||||
PT p { std::allocator_arg_t{}, test_allocator<A>{}, VPT {}};
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// packaged_task(packaged_task&) = delete;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p(p0);
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p(p0);
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// packaged_task();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
struct A {};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::packaged_task<A(int, char)> p;
|
||||
assert(!p.valid());
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// template <class F>
|
||||
// explicit packaged_task(F&& f);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
static int n_moves;
|
||||
static int n_copies;
|
||||
|
||||
explicit A(long i) : data_(i) {}
|
||||
A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
|
||||
A(const A& a) : data_(a.data_) {++n_copies;}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int A::n_moves = 0;
|
||||
int A::n_copies = 0;
|
||||
|
||||
int func(int i) { return i; }
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies == 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
A::n_copies = 0;
|
||||
A::n_copies = 0;
|
||||
{
|
||||
A a(5);
|
||||
std::packaged_task<double(int, char)> p(a);
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies > 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<int(int)> p(&func);
|
||||
assert(p.valid());
|
||||
std::future<int> f = p.get_future();
|
||||
p(4);
|
||||
assert(f.get() == 4);
|
||||
}
|
||||
{
|
||||
std::packaged_task<int(int)> p(func);
|
||||
assert(p.valid());
|
||||
std::future<int> f = p.get_future();
|
||||
p(4);
|
||||
assert(f.get() == 4);
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// template <class F, class Allocator>
|
||||
// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
static int n_moves;
|
||||
static int n_copies;
|
||||
|
||||
explicit A(long i) : data_(i) {}
|
||||
A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
|
||||
A(const A& a) : data_(a.data_) {++n_copies;}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int A::n_moves = 0;
|
||||
int A::n_copies = 0;
|
||||
|
||||
int func(int i) { return i; }
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(std::allocator_arg,
|
||||
test_allocator<A>(), A(5));
|
||||
assert(test_alloc_base::count > 0);
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies == 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
{
|
||||
A a(5);
|
||||
std::packaged_task<double(int, char)> p(std::allocator_arg,
|
||||
test_allocator<A>(), a);
|
||||
assert(test_alloc_base::count > 0);
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies > 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
{
|
||||
A a(5);
|
||||
std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(), &func);
|
||||
assert(test_alloc_base::count > 0);
|
||||
assert(p.valid());
|
||||
std::future<int> f = p.get_future();
|
||||
p(4);
|
||||
assert(f.get() == 4);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
{
|
||||
A a(5);
|
||||
std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(), func);
|
||||
assert(test_alloc_base::count > 0);
|
||||
assert(p.valid());
|
||||
std::future<int> f = p.get_future();
|
||||
p(4);
|
||||
assert(f.get() == 4);
|
||||
}
|
||||
assert(test_alloc_base::count == 0);
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(std::allocator_arg,
|
||||
bare_allocator<void>(), A(5));
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies == 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(std::allocator_arg,
|
||||
min_allocator<void>(), A(5));
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
assert(A::n_copies == 0);
|
||||
assert(A::n_moves > 0);
|
||||
}
|
||||
A::n_copies = 0;
|
||||
A::n_moves = 0;
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// packaged_task(packaged_task&& other);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p = std::move(p0);
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p = std::move(p0);
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// ~packaged_task();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
void func(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
}
|
||||
|
||||
void func2(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
p(3, 'a');
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func, std::move(p)).detach();
|
||||
try
|
||||
{
|
||||
double i = f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func2, std::move(p)).detach();
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// future<R> get_future();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
try
|
||||
{
|
||||
f = p.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::future_already_retrieved));
|
||||
}
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p;
|
||||
try
|
||||
{
|
||||
std::future<double> f = p.get_future();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// void make_ready_at_thread_exit(ArgTypes... args);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const
|
||||
{
|
||||
if (j == 'z')
|
||||
throw A(6);
|
||||
return data_ + i + j;
|
||||
}
|
||||
};
|
||||
|
||||
void func0(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
p.make_ready_at_thread_exit(3, 'a');
|
||||
}
|
||||
|
||||
void func1(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
p.make_ready_at_thread_exit(3, 'z');
|
||||
}
|
||||
|
||||
void func2(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
p.make_ready_at_thread_exit(3, 'a');
|
||||
try
|
||||
{
|
||||
p.make_ready_at_thread_exit(3, 'c');
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
|
||||
void func3(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p.make_ready_at_thread_exit(3, 'a');
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func0, std::move(p)).detach();
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func1, std::move(p)).detach();
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& e)
|
||||
{
|
||||
assert(e(3, 'a') == 106);
|
||||
}
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func2, std::move(p)).detach();
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p;
|
||||
std::thread t(func3, std::move(p));
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// void operator()(ArgTypes... args);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const
|
||||
{
|
||||
if (j == 'z')
|
||||
throw A(6);
|
||||
return data_ + i + j;
|
||||
}
|
||||
};
|
||||
|
||||
void func0(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
p(3, 'a');
|
||||
}
|
||||
|
||||
void func1(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
p(3, 'z');
|
||||
}
|
||||
|
||||
void func2(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
p(3, 'a');
|
||||
try
|
||||
{
|
||||
p(3, 'c');
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
|
||||
}
|
||||
}
|
||||
|
||||
void func3(std::packaged_task<double(int, char)> p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p(3, 'a');
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func0, std::move(p)).detach();
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread(func1, std::move(p)).detach();
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& e)
|
||||
{
|
||||
assert(e(3, 'a') == 106);
|
||||
}
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
std::thread t(func2, std::move(p));
|
||||
assert(f.get() == 105.0);
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p;
|
||||
std::thread t(func3, std::move(p));
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// void reset();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const
|
||||
{
|
||||
if (j == 'z')
|
||||
throw A(6);
|
||||
return data_ + i + j;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p(A(5));
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
p.reset();
|
||||
p(4, 'a');
|
||||
f = p.get_future();
|
||||
assert(f.get() == 106.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p;
|
||||
try
|
||||
{
|
||||
p.reset();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::future_error& e)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// void swap(packaged_task& other);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p.swap(p0);
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p;
|
||||
p.swap(p0);
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// template <class R, class... ArgTypes>
|
||||
// void
|
||||
// swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
long data_;
|
||||
|
||||
public:
|
||||
explicit A(long i) : data_(i) {}
|
||||
|
||||
long operator()(long i, long j) const {return data_ + i + j;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0(A(5));
|
||||
std::packaged_task<double(int, char)> p;
|
||||
swap(p, p0);
|
||||
assert(!p0.valid());
|
||||
assert(p.valid());
|
||||
std::future<double> f = p.get_future();
|
||||
p(3, 'a');
|
||||
assert(f.get() == 105.0);
|
||||
}
|
||||
{
|
||||
std::packaged_task<double(int, char)> p0;
|
||||
std::packaged_task<double(int, char)> p;
|
||||
swap(p, p0);
|
||||
assert(!p0.valid());
|
||||
assert(!p.valid());
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 packaged_task<R(ArgTypes...)>
|
||||
|
||||
// template <class Callable, class Alloc>
|
||||
// struct uses_allocator<packaged_task<Callable>, Alloc>
|
||||
// : true_type { };
|
||||
|
||||
#include <future>
|
||||
#include "../../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::uses_allocator<std::packaged_task<double(int, char)>, test_allocator<int> >::value), "");
|
||||
}
|
28
test/std/thread/futures/futures.tas/types.pass.cpp
Normal file
28
test/std/thread/futures/futures.tas/types.pass.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// template<class R, class... ArgTypes>
|
||||
// class packaged_task<R(ArgTypes...)>
|
||||
// {
|
||||
// public:
|
||||
// typedef R result_type;
|
||||
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
|
||||
struct A {};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), "");
|
||||
}
|
@@ -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
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
68
test/std/thread/futures/futures.unique_future/dtor.pass.cpp
Normal file
68
test/std/thread/futures/futures.unique_future/dtor.pass.cpp
Normal file
@@ -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);
|
||||
}
|
145
test/std/thread/futures/futures.unique_future/get.pass.cpp
Normal file
145
test/std/thread/futures/futures.unique_future/get.pass.cpp
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
68
test/std/thread/futures/futures.unique_future/share.pass.cpp
Normal file
68
test/std/thread/futures/futures.unique_future/share.pass.cpp
Normal file
@@ -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());
|
||||
}
|
||||
}
|
88
test/std/thread/futures/futures.unique_future/wait.pass.cpp
Normal file
88
test/std/thread/futures/futures.unique_future/wait.pass.cpp
Normal file
@@ -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));
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
||||
}
|
@@ -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 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::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::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::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));
|
||||
}
|
||||
}
|
157
test/std/thread/futures/test_allocator.h
Normal file
157
test/std/thread/futures/test_allocator.h
Normal file
@@ -0,0 +1,157 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef TEST_ALLOCATOR_H
|
||||
#define TEST_ALLOCATOR_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <climits>
|
||||
|
||||
class test_alloc_base
|
||||
{
|
||||
public:
|
||||
static int count;
|
||||
public:
|
||||
static int throw_after;
|
||||
};
|
||||
|
||||
int test_alloc_base::count = 0;
|
||||
int test_alloc_base::throw_after = INT_MAX;
|
||||
|
||||
template <class T>
|
||||
class test_allocator
|
||||
: public test_alloc_base
|
||||
{
|
||||
int data_;
|
||||
|
||||
template <class U> friend class test_allocator;
|
||||
public:
|
||||
|
||||
typedef unsigned size_type;
|
||||
typedef int difference_type;
|
||||
typedef T value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef typename std::add_lvalue_reference<value_type>::type reference;
|
||||
typedef typename std::add_lvalue_reference<const value_type>::type const_reference;
|
||||
|
||||
template <class U> struct rebind {typedef test_allocator<U> other;};
|
||||
|
||||
test_allocator() throw() : data_(-1) {}
|
||||
explicit test_allocator(int i) throw() : data_(i) {}
|
||||
test_allocator(const test_allocator& a) throw()
|
||||
: data_(a.data_) {}
|
||||
template <class U> test_allocator(const test_allocator<U>& a) throw()
|
||||
: data_(a.data_) {}
|
||||
~test_allocator() throw() {data_ = 0;}
|
||||
pointer address(reference x) const {return &x;}
|
||||
const_pointer address(const_reference x) const {return &x;}
|
||||
pointer allocate(size_type n, const void* = 0)
|
||||
{
|
||||
if (count >= throw_after) {
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw std::bad_alloc();
|
||||
#else
|
||||
std::terminate();
|
||||
#endif
|
||||
}
|
||||
++count;
|
||||
return (pointer)std::malloc(n * sizeof(T));
|
||||
}
|
||||
void deallocate(pointer p, size_type n)
|
||||
{--count; std::free(p);}
|
||||
size_type max_size() const throw()
|
||||
{return UINT_MAX / sizeof(T);}
|
||||
void construct(pointer p, const T& val)
|
||||
{::new(p) T(val);}
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
void construct(pointer p, T&& val)
|
||||
{::new(p) T(std::move(val));}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
void destroy(pointer p) {p->~T();}
|
||||
|
||||
friend bool operator==(const test_allocator& x, const test_allocator& y)
|
||||
{return x.data_ == y.data_;}
|
||||
friend bool operator!=(const test_allocator& x, const test_allocator& y)
|
||||
{return !(x == y);}
|
||||
};
|
||||
|
||||
template <>
|
||||
class test_allocator<void>
|
||||
: public test_alloc_base
|
||||
{
|
||||
int data_;
|
||||
|
||||
template <class U> friend class test_allocator;
|
||||
public:
|
||||
|
||||
typedef unsigned size_type;
|
||||
typedef int difference_type;
|
||||
typedef void value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
|
||||
template <class U> struct rebind {typedef test_allocator<U> other;};
|
||||
|
||||
test_allocator() throw() : data_(-1) {}
|
||||
explicit test_allocator(int i) throw() : data_(i) {}
|
||||
test_allocator(const test_allocator& a) throw()
|
||||
: data_(a.data_) {}
|
||||
template <class U> test_allocator(const test_allocator<U>& a) throw()
|
||||
: data_(a.data_) {}
|
||||
~test_allocator() throw() {data_ = 0;}
|
||||
|
||||
friend bool operator==(const test_allocator& x, const test_allocator& y)
|
||||
{return x.data_ == y.data_;}
|
||||
friend bool operator!=(const test_allocator& x, const test_allocator& y)
|
||||
{return !(x == y);}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class other_allocator
|
||||
{
|
||||
int data_;
|
||||
|
||||
template <class U> friend class other_allocator;
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
other_allocator() : data_(-1) {}
|
||||
explicit other_allocator(int i) : data_(i) {}
|
||||
template <class U> other_allocator(const other_allocator<U>& a)
|
||||
: data_(a.data_) {}
|
||||
T* allocate(std::size_t n)
|
||||
{return (T*)std::malloc(n * sizeof(T));}
|
||||
void deallocate(T* p, std::size_t n)
|
||||
{std::free(p);}
|
||||
|
||||
other_allocator select_on_container_copy_construction() const
|
||||
{return other_allocator(-2);}
|
||||
|
||||
friend bool operator==(const other_allocator& x, const other_allocator& y)
|
||||
{return x.data_ == y.data_;}
|
||||
friend bool operator!=(const other_allocator& x, const other_allocator& y)
|
||||
{return !(x == y);}
|
||||
|
||||
typedef std::true_type propagate_on_container_copy_assignment;
|
||||
typedef std::true_type propagate_on_container_move_assignment;
|
||||
typedef std::true_type propagate_on_container_swap;
|
||||
|
||||
#ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
std::size_t max_size() const
|
||||
{return UINT_MAX / sizeof(T);}
|
||||
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
|
||||
};
|
||||
|
||||
#endif // TEST_ALLOCATOR_H
|
22
test/std/thread/futures/version.pass.cpp
Normal file
22
test/std/thread/futures/version.pass.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
#include <future>
|
||||
|
||||
#ifndef _LIBCPP_VERSION
|
||||
#error _LIBCPP_VERSION not defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
23
test/std/thread/macro.pass.cpp
Normal file
23
test/std/thread/macro.pass.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <thread>
|
||||
|
||||
// #define __STDCPP_THREADS__ __cplusplus
|
||||
|
||||
#include <thread>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef __STDCPP_THREADS__
|
||||
#error __STDCPP_THREADS__ is not defined
|
||||
#endif
|
||||
}
|
23
test/std/thread/thread.condition/cv_status.pass.cpp
Normal file
23
test/std/thread/thread.condition/cv_status.pass.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// enum class cv_status { no_timeout, timeout };
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(static_cast<int>(std::cv_status::no_timeout) == 0);
|
||||
assert(static_cast<int>(std::cv_status::timeout) == 1);
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// void
|
||||
// notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::high_resolution_clock Clock;
|
||||
|
||||
void func()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
std::notify_all_at_thread_exit(cv, std::move(lk));
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
std::thread(func).detach();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
cv.wait(lk);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
assert(t1-t0 > ms(250));
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable& operator=(const condition_variable&) = delete;
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable cv0;
|
||||
std::condition_variable cv1;
|
||||
cv1 = cv0;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable cv0;
|
||||
std::condition_variable cv1(cv0);
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable cv;
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// ~condition_variable();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable* cv;
|
||||
std::mutex m;
|
||||
typedef std::unique_lock<std::mutex> Lock;
|
||||
|
||||
bool f_ready = false;
|
||||
bool g_ready = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
Lock lk(m);
|
||||
f_ready = true;
|
||||
cv->notify_one();
|
||||
delete cv;
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
Lock lk(m);
|
||||
g_ready = true;
|
||||
cv->notify_one();
|
||||
while (!f_ready)
|
||||
cv->wait(lk);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cv = new std::condition_variable;
|
||||
std::thread th2(g);
|
||||
Lock lk(m);
|
||||
while (!g_ready)
|
||||
cv->wait(lk);
|
||||
lk.unlock();
|
||||
std::thread th1(f);
|
||||
th1.join();
|
||||
th2.join();
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// typedef pthread_cond_t* native_handle_type;
|
||||
// native_handle_type native_handle();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::condition_variable::native_handle_type,
|
||||
pthread_cond_t*>::value), "");
|
||||
std::condition_variable cv;
|
||||
std::condition_variable::native_handle_type h = cv.native_handle();
|
||||
assert(h != nullptr);
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// void notify_all();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test0 = 0;
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 == 1);
|
||||
test1 = 2;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
while (test2 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test2 == 1);
|
||||
test2 = 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::thread t1(f1);
|
||||
std::thread t2(f2);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
test1 = 1;
|
||||
test2 = 1;
|
||||
}
|
||||
cv.notify_all();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
assert(test1 == 2);
|
||||
assert(test2 == 2);
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// void notify_one();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test0 = 0;
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 == 1);
|
||||
test1 = 2;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
while (test2 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test2 == 1);
|
||||
test2 = 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::thread t1(f1);
|
||||
std::thread t2(f2);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
test1 = 1;
|
||||
test2 = 1;
|
||||
}
|
||||
cv.notify_one();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
}
|
||||
if (test1 == 2)
|
||||
{
|
||||
t1.join();
|
||||
test1 = 0;
|
||||
}
|
||||
else if (test2 == 2)
|
||||
{
|
||||
t2.join();
|
||||
test2 = 0;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
cv.notify_one();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
}
|
||||
if (test1 == 2)
|
||||
{
|
||||
t1.join();
|
||||
test1 = 0;
|
||||
}
|
||||
else if (test2 == 2)
|
||||
{
|
||||
t2.join();
|
||||
test2 = 0;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// void wait(unique_lock<mutex>& lock);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
while (test2 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test2 != 0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// template <class Rep, class Period>
|
||||
// cv_status
|
||||
// wait_for(unique_lock<mutex>& lock,
|
||||
// const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef std::chrono::milliseconds milliseconds;
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
while (test2 == 0 &&
|
||||
cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
|
||||
;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
assert(t1 - t0 < milliseconds(250));
|
||||
assert(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
|
||||
assert(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// template <class Rep, class Period, class Predicate>
|
||||
// bool
|
||||
// wait_for(unique_lock<mutex>& lock,
|
||||
// const chrono::duration<Rep, Period>& rel_time,
|
||||
// Predicate pred);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) : i_(i) {}
|
||||
|
||||
bool operator()() {return i_ != 0;}
|
||||
};
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef std::chrono::milliseconds milliseconds;
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
assert(t1 - t0 < milliseconds(250));
|
||||
assert(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
|
||||
assert(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// template <class Predicate>
|
||||
// void wait(unique_lock<mutex>& lock, Predicate pred);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) : i_(i) {}
|
||||
|
||||
bool operator()() {return i_ != 0;}
|
||||
};
|
||||
|
||||
void f()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
cv.wait(lk, Pred(test2));
|
||||
assert(test2 != 0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// template <class Clock, class Duration>
|
||||
// cv_status
|
||||
// wait_until(unique_lock<mutex>& lock,
|
||||
// const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef std::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef std::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return time_point(duration_cast<duration>(
|
||||
steady_clock::now().time_since_epoch()
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout)
|
||||
;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
assert(t1 - t0 < Clock::duration(250));
|
||||
assert(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(t1 - t0 - Clock::duration(250) < Clock::duration(50));
|
||||
assert(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// template <class Clock, class Duration, class Predicate>
|
||||
// bool
|
||||
// wait_until(unique_lock<mutex>& lock,
|
||||
// const chrono::time_point<Clock, Duration>& abs_time,
|
||||
// Predicate pred);
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef std::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef std::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return time_point(duration_cast<duration>(
|
||||
steady_clock::now().time_since_epoch()
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) : i_(i) {}
|
||||
|
||||
bool operator()() {return i_ != 0;}
|
||||
};
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
assert(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
bool r = cv.wait_until(lk, t, Pred(test2));
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
assert(t1 - t0 < Clock::duration(250));
|
||||
assert(test2 != 0);
|
||||
assert(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(t1 - t0 - Clock::duration(250) < Clock::duration(50));
|
||||
assert(test2 == 0);
|
||||
assert(!r);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex>lk(mut);
|
||||
std::thread t(f);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any& operator=(const condition_variable_any&) = delete;
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable_any cv0;
|
||||
std::condition_variable_any cv1;
|
||||
cv1 = cv0;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable_any cv0;
|
||||
std::condition_variable_any cv1(cv0);
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable_any cv;
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// ~condition_variable_any();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable_any* cv;
|
||||
std::mutex m;
|
||||
|
||||
bool f_ready = false;
|
||||
bool g_ready = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
m.lock();
|
||||
f_ready = true;
|
||||
cv->notify_one();
|
||||
delete cv;
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
m.lock();
|
||||
g_ready = true;
|
||||
cv->notify_one();
|
||||
while (!f_ready)
|
||||
cv->wait(m);
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cv = new std::condition_variable_any;
|
||||
std::thread th2(g);
|
||||
m.lock();
|
||||
while (!g_ready)
|
||||
cv->wait(m);
|
||||
m.unlock();
|
||||
std::thread th1(f);
|
||||
th1.join();
|
||||
th2.join();
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// void notify_all();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable_any cv;
|
||||
|
||||
typedef std::timed_mutex L0;
|
||||
typedef std::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test0 = 0;
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
void f1()
|
||||
{
|
||||
L1 lk(m0);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 == 1);
|
||||
test1 = 2;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
L1 lk(m0);
|
||||
assert(test2 == 0);
|
||||
while (test2 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test2 == 1);
|
||||
test2 = 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::thread t1(f1);
|
||||
std::thread t2(f2);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
{
|
||||
L1 lk(m0);
|
||||
test1 = 1;
|
||||
test2 = 1;
|
||||
}
|
||||
cv.notify_all();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
L1 lk(m0);
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
assert(test1 == 2);
|
||||
assert(test2 == 2);
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <condition_variable>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// void notify_one();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
std::condition_variable_any cv;
|
||||
|
||||
typedef std::timed_mutex L0;
|
||||
typedef std::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test0 = 0;
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
void f1()
|
||||
{
|
||||
L1 lk(m0);
|
||||
assert(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test1 == 1);
|
||||
test1 = 2;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
L1 lk(m0);
|
||||
assert(test2 == 0);
|
||||
while (test2 == 0)
|
||||
cv.wait(lk);
|
||||
assert(test2 == 1);
|
||||
test2 = 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::thread t1(f1);
|
||||
std::thread t2(f2);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
{
|
||||
L1 lk(m0);
|
||||
test1 = 1;
|
||||
test2 = 1;
|
||||
}
|
||||
cv.notify_one();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
L1 lk(m0);
|
||||
}
|
||||
if (test1 == 2)
|
||||
{
|
||||
t1.join();
|
||||
test1 = 0;
|
||||
}
|
||||
else if (test2 == 2)
|
||||
{
|
||||
t2.join();
|
||||
test2 = 0;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
cv.notify_one();
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
L1 lk(m0);
|
||||
}
|
||||
if (test1 == 2)
|
||||
{
|
||||
t1.join();
|
||||
test1 = 0;
|
||||
}
|
||||
else if (test2 == 2)
|
||||
{
|
||||
t2.join();
|
||||
test2 = 0;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
struct Mutex
|
||||
{
|
||||
unsigned state = 0;
|
||||
Mutex() = default;
|
||||
~Mutex() = default;
|
||||
Mutex(const Mutex&) = delete;
|
||||
Mutex& operator=(const Mutex&) = delete;
|
||||
|
||||
void lock()
|
||||
{
|
||||
if (++state == 2)
|
||||
throw 1; // this throw should end up calling terminate()
|
||||
}
|
||||
|
||||
void unlock() {}
|
||||
};
|
||||
|
||||
Mutex mut;
|
||||
std::condition_variable_any cv;
|
||||
|
||||
void
|
||||
signal_me()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
cv.notify_one();
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
try
|
||||
{
|
||||
std::thread(signal_me).detach();
|
||||
mut.lock();
|
||||
cv.wait(mut);
|
||||
}
|
||||
catch (...) {}
|
||||
assert(false);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user