N3188 - Revision to N3113: Async Launch Policies (CH 36)

llvm-svn: 120027
This commit is contained in:
Howard Hinnant 2010-11-23 18:33:54 +00:00
parent 60813f96e0
commit e3120ed1bf
4 changed files with 19 additions and 19 deletions

View File

@ -27,9 +27,9 @@ enum class future_errc
enum class launch
{
any,
async,
sync
async = 1,
deferred = 2,
any = async | deferred
};
enum class future_status
@ -470,9 +470,9 @@ struct _LIBCPP_VISIBLE is_error_code_enum<future_errc> : public true_type {};
struct _LIBCPP_VISIBLE launch
{
enum _ {
any,
async,
sync
async = 1,
deferred = 2,
any = async | deferred
};
_ __v_;
@ -2111,16 +2111,16 @@ async(launch __policy, _F&& __f, _Args&&... __args)
{
typedef typename result_of<_F(_Args...)>::type _R;
future<_R> __r;
if (__policy == launch::sync)
__r = _STD::__make_deferred_assoc_state<_R>(bind(_STD::forward<_F>(__f),
_STD::forward<_Args>(__args)...));
else
if (__policy & launch::async)
{
packaged_task<_R()> __pk(bind(_STD::forward<_F>(__f),
_STD::forward<_Args>(__args)...));
__r = __pk.get_future();
thread(_STD::move(__pk)).detach();
}
else if (__policy & launch::deferred)
__r = _STD::__make_deferred_assoc_state<_R>(bind(_STD::forward<_F>(__f),
_STD::forward<_Args>(__args)...));
return __r;
}

View File

@ -1395,7 +1395,7 @@ public:
};
template <class _MP, class _Tp, class ..._Args>
struct __result_of_mp;
struct __result_of_mp {};
// member function pointer

View File

@ -82,7 +82,7 @@ int main()
assert(t1-t0 < ms(100));
}
{
std::future<int> f = std::async(std::launch::sync, f0);
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);
@ -115,7 +115,7 @@ int main()
assert(t1-t0 < ms(100));
}
{
std::future<int&> f = std::async(std::launch::sync, f1);
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);
@ -148,7 +148,7 @@ int main()
assert(t1-t0 < ms(100));
}
{
std::future<void> f = std::async(std::launch::sync, f2);
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();

View File

@ -11,16 +11,16 @@
// enum class launch
// {
// any,
// async,
// sync
// async = 1,
// deferred = 2,
// any = async | deferred
// };
#include <future>
int main()
{
static_assert(std::launch::any == 0, "");
static_assert(std::launch::any == std::launch::async | std::launch::deferred, "");
static_assert(std::launch::async == 1, "");
static_assert(std::launch::sync == 2, "");
static_assert(std::launch::deferred == 2, "");
}