本文整理汇总了C++中future类的典型用法代码示例。如果您正苦于以下问题:C++ future类的具体用法?C++ future怎么用?C++ future使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了future类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
void apply(future<void> f) const
{
if (f.ready())
return;
task_context* ctx = current_task_context::get();
if (!ctx)
{
f.wait();
return;
}
auto&& resume_task = [=]() {
ctx->resume();
};
auto s = f.get_state(detail::use_private_interface);
s->continue_with([&]() {
s->await_queue()->push_front([=]() {
resume_task();
});
});
ctx->yield();
}
示例2: future_answer
void future_answer()
{
//int x=the_answer_to_life_the_universe_and_everything.get_future().get();
//如果上面注释的这句话就会出错!
int x=fut.get();
cout<<x<<endl;
}
示例3: operator
type operator()(future<T> const& x) const
{
if (auto&& state = x.get_state(use_private_interface))
return state->template then<future<void>>(std::bind([](){}));
else
return make_ready_future();
}
示例4: migrate_component_postproc
future<naming::id_type> migrate_component_postproc(
future<boost::shared_ptr<Component> > f,
naming::id_type const& to_migrate,
naming::id_type const& target_locality)
{
using components::stubs::runtime_support;
boost::shared_ptr<Component> ptr = f.get();
boost::uint32_t pin_count = ptr->pin_count();
if (pin_count == ~0x0u)
{
HPX_THROW_EXCEPTION(invalid_status,
"hpx::components::server::migrate_component",
"attempting to migrate an instance of a component which was "
"already migrated");
return make_ready_future(naming::invalid_id);
}
if (pin_count > 1)
{
HPX_THROW_EXCEPTION(invalid_status,
"hpx::components::server::migrate_component",
"attempting to migrate an instance of a component which is "
"currently pinned");
return make_ready_future(naming::invalid_id);
}
return runtime_support::migrate_component_async<Component>(
target_locality, ptr, to_migrate)
.then(util::bind(
&detail::migrate_component_cleanup<Component>,
util::placeholders::_1, ptr, to_migrate));
}
示例5: crypto_one_test
static
void crypto_one_test(const string &name, future<ContextReply> context, const vector<uint8_t> expected)
{
auto result = context.get().data;
if (!equal(expected.begin(), expected.end(), result.begin())) {
throw runtime_error(name + ": Ошибка тестирования");
}
}
示例6: migrate_to_storage_here_cleanup
naming::id_type migrate_to_storage_here_cleanup(
future<naming::id_type> f,
boost::shared_ptr<Component> ptr,
naming::id_type const& to_migrate)
{
ptr->mark_as_migrated();
return f.get();
}
示例7: factorial
/* Asynchronously provide data with promise */
int factorial(future<int>& f) {
// do something else
int N = f.get(); // If promise is distroyed, exception: std::future_errc::broken_promise
cout << "Got from parent: " << N << endl;
int res = 1;
for (int i=N; i>1; i--)
res *= i;
return res;
}
示例8: promiseDependingFunction
int promiseDependingFunction(future<int>& fu) {
//... do some work setting up the environment...
this_thread::sleep_for(chrono::milliseconds(100));
//ready to wait for promise to be fufilled
int value = fu.get();
//use value
value *= 16;
return value;
}
示例9: get_exception_ptr
template<typename T> inline exception_ptr get_exception_ptr(future<T> &f)
{
#if 1
// Thanks to Vicente for adding this to Boost.Thread
return f.get_exception_ptr();
#else
// This seems excessive but I don't see any other legal way to extract the exception ...
bool success=false;
try
{
f.get();
success=true;
}
catch(...)
{
exception_ptr e(afio::make_exception_ptr(afio::current_exception()));
assert(e);
return e;
}
return exception_ptr();
#endif
}
示例10: operator
void operator()(future<double> r) const
{
global_scratch += r.get();
}
示例11: operator
HPX_FORCEINLINE result_type
operator()(future<Derived> f) const
{
return f.get().share();
}
示例12: producer
void
producer( future & f )
{
f.set_exception (boost::copy_exception (err () << answer(42)));
}
示例13: future
future(const future<T> &other)
: m_event(other.get_event())
{
}
示例14: future_int_f1
int future_int_f1(future<void> f1)
{
HPX_TEST(f1.is_ready());
++future_int_f1_count;
return 1;
}
示例15: call
static future<Result> call(future<Result> f)
{
HPX_ASSERT(f.has_exception());
// Intel complains if this is not explicitly moved
return std::move(f);
}