Suppress condition/mutex/thread stuff.
This commit is contained in:
@@ -14,7 +14,35 @@
|
||||
#include <__config>
|
||||
#include <chrono>
|
||||
#include <system_error>
|
||||
#ifdef __MINGW32__
|
||||
typedef unsigned pthread_t;
|
||||
typedef unsigned pthread_mutex_t;
|
||||
typedef unsigned pthread_mutexattr_t;
|
||||
typedef unsigned pthread_cond_t;
|
||||
typedef unsigned pthread_key_t;
|
||||
#define PTHREAD_MUTEX_INITIALIZER 0
|
||||
#define PTHREAD_COND_INITIALIZER 0
|
||||
#define PTHREAD_MUTEX_RECURSIVE 0
|
||||
#define pthread_mutex_init(a,b) (*(a) = 0, -1)
|
||||
#define pthread_mutex_destroy(a) (-1)
|
||||
#define pthread_mutex_lock(a) (-1)
|
||||
#define pthread_mutex_trylock(a) (-1)
|
||||
#define pthread_mutex_unlock(a) (-1)
|
||||
#define pthread_mutexattr_settype(a,b) (*(a) = (b), -1)
|
||||
#define pthread_mutexattr_init(a) (*(a) = 0, -1)
|
||||
#define pthread_mutexattr_destroy(a) (-1)
|
||||
#define pthread_self() (-1)
|
||||
#define pthread_equal(a,b) (0)
|
||||
#define pthread_getspecific(a) ((void*)0)
|
||||
#define pthread_cond_destroy(a) (-1)
|
||||
#define pthread_cond_signal(a) (-1)
|
||||
#define pthread_cond_broadcast(a) (-1)
|
||||
#define pthread_cond_wait(a,b) (-1)
|
||||
#define pthread_cond_timedwait(a,b,c) (-1)
|
||||
#define sched_yield() (-1)
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#pragma GCC system_header
|
||||
|
||||
|
@@ -95,7 +95,15 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
#include <system_error>
|
||||
#include <chrono>
|
||||
#include <__mutex_base>
|
||||
#ifdef __MINGW32__
|
||||
#define pthread_key_delete(a) (-1)
|
||||
#define pthread_join(a,b) (-1)
|
||||
#define pthread_detach(a) (-1)
|
||||
#define nanosleep(a,b) (-1)
|
||||
#define pthread_key_create(a,b) (-1)
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#pragma GCC system_header
|
||||
|
||||
|
@@ -57,8 +57,10 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
|
||||
ts.tv_sec = static_cast<decltype(ts.tv_sec)>(s.count());
|
||||
ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
|
||||
int ec = pthread_cond_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
|
||||
#ifndef __MINGW32__
|
||||
if (ec != 0 && ec != ETIMEDOUT)
|
||||
__throw_system_error(ec, "condition_variable timed_wait failed");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -12,7 +12,10 @@
|
||||
#include "vector"
|
||||
#include "future"
|
||||
#include <sys/types.h>
|
||||
#ifdef __MINGW32__
|
||||
#else
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
|
@@ -1,177 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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(std::errc::not_a_directory);
|
||||
assert(e_cond.category() == e_cat);
|
||||
assert(e_cond.value() == std::errc::not_a_directory);
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_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);
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_error : public logic_error {...};
|
||||
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_convertible<std::future_error*,
|
||||
std::logic_error*>::value), "");
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_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);
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class future_errc
|
||||
// {
|
||||
// broken_promise,
|
||||
// future_already_retrieved,
|
||||
// promise_already_satisfied,
|
||||
// no_state
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::future_errc::broken_promise == 0, "");
|
||||
static_assert(std::future_errc::future_already_retrieved == 1, "");
|
||||
static_assert(std::future_errc::promise_already_satisfied == 2, "");
|
||||
static_assert(std::future_errc::no_state == 3, "");
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class future_status
|
||||
// {
|
||||
// ready,
|
||||
// timeout,
|
||||
// deferred
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::future_status::ready == 0, "");
|
||||
static_assert(std::future_status::timeout == 1, "");
|
||||
static_assert(std::future_status::deferred == 2, "");
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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, "");
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class launch
|
||||
// {
|
||||
// async = 1,
|
||||
// deferred = 2,
|
||||
// any = async | deferred
|
||||
// };
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::launch::any == std::launch::async | std::launch::deferred, "");
|
||||
static_assert(std::launch::async == 1, "");
|
||||
static_assert(std::launch::deferred == 2, "");
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// template <class Allocator>
|
||||
// promise(allocator_arg_t, const Allocator& a);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_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);
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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)
|
||||
{
|
||||
assert(e.code() == make_error_code(std::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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=(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
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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(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
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,82 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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);
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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), "");
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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);
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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));
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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));
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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));
|
||||
}
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
// -*- 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()
|
||||
{
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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&& 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());
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
struct A {};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::packaged_task<A(int, char)> p;
|
||||
assert(!p.valid());
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
// 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 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);
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../test_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 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_copies = 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);
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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&& 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());
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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...)>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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...)>
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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...)>
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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...)>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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...)>
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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());
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 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), "");
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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), "");
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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);
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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=(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
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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(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
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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(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_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::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));
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
#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)
|
||||
throw std::bad_alloc();
|
||||
++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
|
@@ -1,20 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
#include <future>
|
||||
|
||||
#ifndef _LIBCPP_VERSION
|
||||
#error _LIBCPP_VERSION not defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <thread>
|
||||
|
||||
// #define __STDCPP_THREADS__ __cplusplus
|
||||
|
||||
#include <thread>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef __STDCPP_THREADS__
|
||||
#error __STDCPP_THREADS__ is not defined
|
||||
#endif
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// enum class cv_status { no_timeout, timeout };
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::cv_status::no_timeout == 0);
|
||||
assert(std::cv_status::timeout == 1);
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// 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));
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable cv;
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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();
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
}
|
@@ -1,92 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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();
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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(5));
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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(2));
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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();
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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(5));
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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(2));
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::condition_variable_any cv;
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#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();
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user