Example #1
0
File: await.hpp Project: hkr/ltl
 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();
 }
Example #2
0
 void future_answer()
 {
     //int x=the_answer_to_life_the_universe_and_everything.get_future().get();
     //如果上面注释的这句话就会出错!
     int x=fut.get();
     cout<<x<<endl;
 }
Example #3
0
File: when_all.hpp Project: hkr/ltl
 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();
 }
Example #4
0
        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));
        }
Example #5
0
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 + ": Ошибка тестирования");
	}
}
Example #6
0
 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();
 }
Example #7
0
 ~impl()
 {
    try
    {
      _rotation_task.cancel_and_wait("file_appender is destructing");
    }
    catch( ... )
    {
    }
 }
Example #8
0
/* 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;
}
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;
}
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
}
Example #11
0
 void operator()(future<double> r) const
 {
     global_scratch += r.get();
 }
Example #12
0
 HPX_FORCEINLINE result_type
 operator()(future<Derived> f) const
 {
     return f.get().share();
 }
void
producer( future & f )
    {
    f.set_exception (boost::copy_exception (err () << answer(42)));
    }
Example #14
0
 future(const future<T> &other)
     : m_event(other.get_event())
 {
 }
Example #15
0
int future_int_f1(future<void> f1)
{
    HPX_TEST(f1.is_ready());
    ++future_int_f1_count;
    return 1;
}
Example #16
0
 bool valid() const { return listener.valid(); }
Example #17
0
 static future<Result> call(future<Result> f)
 {
     HPX_ASSERT(f.has_exception());
     // Intel complains if this is not explicitly moved
     return std::move(f);
 }
Example #18
0
 shared_future(future<T>&& future)
     : state(new shared_state_multiplexer<T>(std::move(future)) )
     , listener(state->add_listener())
 {
     assert(listener.valid());
 }
Example #19
0
void worker1(future<int> fut) {
    printf("this is thread1\n");
    flag = 1;
    fut.get();
    printf("thread1 exit\n");
}
Example #20
0
 int operator()(future<int> msg) {
     int id = Futures_Id();
     std::cout << "Waiting for future on " << id << endl;
     return msg.get();
 };
Example #21
0
void future_void_f1(future<void> f1)
{
    HPX_TEST(f1.is_ready());
    ++future_void_f1_count;
}
Example #22
0
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();
}
Example #23
0
 static bool erase_vorbis_stream(const future<vector<float>>& fut)
 {
    return !fut.valid();
 }
Example #24
0
 bool ready() const { return listener.ready(); }
Example #25
0
 void insert(const future<T> &future)
 {
     insert(future.get_event());
 }
Example #26
0
 void wait(WaitStrategy&& strategy) {
     listener.wait(strategy);
 }
Example #27
0
// This function will be called for every file opened
static void open_file_filter(detail::OpType, future<> &op) noexcept
{
    std::cout << "File handle " << op->native_handle() << " opened!" << std::endl;
}
Example #28
0
 void wait() {
     listener.wait();
 }
Example #29
0
 shared_future(const shared_future& rhs)
     : state(rhs.state)
     , listener(state ? state->add_listener() : future<bool>())
 {
     assert(listener.valid());
 }
Example #30
0
void future_void_f2(future<void> f1, future<void> f2)
{
    HPX_TEST(f1.is_ready());
    HPX_TEST(f2.is_ready());
    ++future_void_f2_count;
}