本文整理汇总了C++中future类的典型用法代码示例。如果您正苦于以下问题:C++ future类的具体用法?C++ future怎么用?C++ future使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了future类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:hkr,项目名称:ltl,代码行数:26,代码来源:await.hpp
示例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;
}
开发者ID:QiTai,项目名称:CPP_Thread,代码行数:7,代码来源:FuturePromise.cpp
示例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();
}
开发者ID:hkr,项目名称:ltl,代码行数:7,代码来源:when_all.hpp
示例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));
}
开发者ID:AntonBikineev,项目名称:hpx,代码行数:33,代码来源:migrate_component.hpp
示例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 + ": Ошибка тестирования");
}
}
开发者ID:DronMDF,项目名称:async-gost,代码行数:8,代码来源:CryptoTest.cpp
示例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();
}
开发者ID:Bcorde5,项目名称:hpx,代码行数:8,代码来源:migrate_to_storage.hpp
示例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;
}
开发者ID:MiichaelD,项目名称:c_cpp,代码行数:12,代码来源:threads_ch4.cpp
示例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;
}
开发者ID:mattstone22133,项目名称:LearningCppFeatures,代码行数:12,代码来源:7.+FuturePromiseAsync.cpp
示例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
}
开发者ID:EverYoung124,项目名称:boost.afio,代码行数:22,代码来源:std_atomic_mutex_chrono.hpp
示例10: operator
void operator()(future<double> r) const
{
global_scratch += r.get();
}
开发者ID:K-ballo,项目名称:hpx,代码行数:4,代码来源:future_overhead.cpp
示例11: operator
HPX_FORCEINLINE result_type
operator()(future<Derived> f) const
{
return f.get().share();
}
开发者ID:parsa,项目名称:hpx,代码行数:5,代码来源:client_base.hpp
示例12: producer
void
producer( future & f )
{
f.set_exception (boost::copy_exception (err () << answer(42)));
}
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:5,代码来源:copy_exception_test.cpp
示例13: future
future(const future<T> &other)
: m_event(other.get_event())
{
}
开发者ID:junmuz,项目名称:compute,代码行数:4,代码来源:future.hpp
示例14: future_int_f1
int future_int_f1(future<void> f1)
{
HPX_TEST(f1.is_ready());
++future_int_f1_count;
return 1;
}
开发者ID:Bcorde5,项目名称:hpx,代码行数:6,代码来源:local_dataflow_executor.cpp
示例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);
}
开发者ID:ltroska,项目名称:hpx,代码行数:6,代码来源:exception_list.hpp
示例16: shared_future
shared_future(future<T>&& future)
: state(new shared_state_multiplexer<T>(std::move(future)) )
, listener(state->add_listener())
{
assert(listener.valid());
}
开发者ID:viboes,项目名称:libtask,代码行数:6,代码来源:shared_future.hpp
示例17: worker1
void worker1(future<int> fut) {
printf("this is thread1\n");
flag = 1;
fut.get();
printf("thread1 exit\n");
}
开发者ID:evely211,项目名称:Norman,代码行数:6,代码来源:NThreadPromise.cpp
示例18: operator
int operator()(future<int> msg) {
int id = Futures_Id();
std::cout << "Waiting for future on " << id << endl;
return msg.get();
};
开发者ID:k4s4s,项目名称:Distributed-Futures,代码行数:5,代码来源:test.cpp
示例19: future_void_f1
void future_void_f1(future<void> f1)
{
HPX_TEST(f1.is_ready());
++future_void_f1_count;
}
开发者ID:Bcorde5,项目名称:hpx,代码行数:5,代码来源:local_dataflow_executor.cpp
示例20: future_int_f2
int future_int_f2(future<int> f1, future<int> f2)
{
HPX_TEST(f1.is_ready()); HPX_TEST(f2.is_ready());
++future_int_f2_count;
return f1.get() + f2.get();
}
开发者ID:Bcorde5,项目名称:hpx,代码行数:6,代码来源:local_dataflow_executor.cpp
注:本文中的future类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论