本文整理汇总了C++中hpx::make_continuation方法的典型用法代码示例。如果您正苦于以下问题:C++ hpx::make_continuation方法的具体用法?C++ hpx::make_continuation怎么用?C++ hpx::make_continuation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hpx
的用法示例。
在下文中一共展示了hpx::make_continuation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hpx_main
int hpx_main()
{
using hpx::make_continuation;
increment_action inc;
increment_with_future_action inc_f;
mult2_action mult;
// test locally, fully equivalent to plain hpx::async
{
hpx::future<int> f1 = hpx::async_continue(
inc, make_continuation(), hpx::find_here(), 42);
HPX_TEST_EQ(f1.get(), 43);
hpx::promise<std::int32_t> p;
hpx::shared_future<std::int32_t> f = p.get_future();
hpx::future<int> f2 = hpx::async_continue(
inc_f, make_continuation(), hpx::find_here(), f);
p.set_value(42);
HPX_TEST_EQ(f2.get(), 43);
}
// test remotely, if possible, fully equivalent to plain hpx::async
std::vector<hpx::id_type> localities = hpx::find_remote_localities();
if (!localities.empty())
{
hpx::future<int> f1 = hpx::async_continue(
inc, make_continuation(), localities[0], 42);
HPX_TEST_EQ(f1.get(), 43);
hpx::promise<std::int32_t> p;
hpx::shared_future<std::int32_t> f = p.get_future();
hpx::future<int> f2 = hpx::async_continue(
inc_f, make_continuation(), localities[0], f);
p.set_value(42);
HPX_TEST_EQ(f2.get(), 43);
}
// test chaining locally
{
hpx::future<int> f = hpx::async_continue(
inc, make_continuation(mult), hpx::find_here(), 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue(inc,
make_continuation(mult, make_continuation()), hpx::find_here(), 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue(inc,
make_continuation(mult, make_continuation(inc)), hpx::find_here() ,42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue(inc,
make_continuation(mult, make_continuation(inc, make_continuation())),
hpx::find_here(), 42);
HPX_TEST_EQ(f.get(), 87);
}
// test chaining remotely, if possible
if (!localities.empty())
{
hpx::future<int> f = hpx::async_continue(inc,
make_continuation(mult, localities[0]), localities[0], 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue(inc,
make_continuation(mult, localities[0], make_continuation()),
localities[0], 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue(inc,
make_continuation(mult, localities[0],
make_continuation(inc)), localities[0], 42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue(inc,
make_continuation(mult, localities[0],
make_continuation(inc, make_continuation())), localities[0], 42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue(inc,
make_continuation(mult, localities[0],
make_continuation(inc, localities[0])), localities[0], 42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue(inc,
make_continuation(mult, localities[0],
make_continuation(inc, localities[0], make_continuation())),
localities[0], 42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue(inc,
make_continuation(mult), localities[0], 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue(inc,
//.........这里部分代码省略.........
示例2: hpx_main
int hpx_main()
{
using hpx::make_continuation;
increment_action inc;
increment_with_future_action inc_f;
mult2_action mult;
// test locally, fully equivalent to plain hpx::async
{
callback_called.store(0);
hpx::future<int> f1 = hpx::async_continue_cb(
inc, make_continuation(), hpx::find_here(), &cb, 42);
HPX_TEST_EQ(f1.get(), 43);
hpx::promise<std::int32_t> p;
hpx::shared_future<std::int32_t> f = p.get_future();
hpx::future<int> f2 = hpx::async_continue_cb(
inc_f, make_continuation(), hpx::find_here(), &cb, f);
p.set_value(42);
HPX_TEST_EQ(f2.get(), 43);
// The callback should have been called 2 times. wait for a short period
// of time, to allow it for it to be fully executed
hpx::this_thread::sleep_for(std::chrono::milliseconds(100));
HPX_TEST_EQ(callback_called.load(), 2);
}
// test remotely, if possible, fully equivalent to plain hpx::async
std::vector<hpx::id_type> localities = hpx::find_remote_localities();
if (!localities.empty())
{
callback_called.store(0);
hpx::future<int> f1 = hpx::async_continue_cb(
inc, make_continuation(), localities[0], &cb, 42);
HPX_TEST_EQ(f1.get(), 43);
hpx::promise<std::int32_t> p;
hpx::shared_future<std::int32_t> f = p.get_future();
hpx::future<int> f2 = hpx::async_continue_cb(
inc_f, make_continuation(), localities[0], &cb, f);
p.set_value(42);
HPX_TEST_EQ(f2.get(), 43);
// The callback should have been called 2 times. wait for a short period
// of time, to allow it for it to be fully executed
hpx::this_thread::sleep_for(std::chrono::milliseconds(100));
HPX_TEST_EQ(callback_called.load(), 2);
}
// test chaining locally
{
callback_called.store(0);
hpx::future<int> f = hpx::async_continue_cb(
inc, make_continuation(mult), hpx::find_here(), &cb, 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue_cb(inc,
make_continuation(mult, make_continuation()), hpx::find_here(),
&cb, 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue_cb(inc,
make_continuation(mult, make_continuation(inc)), hpx::find_here(),
&cb, 42);
HPX_TEST_EQ(f.get(), 87);
f = hpx::async_continue_cb(inc,
make_continuation(mult, make_continuation(inc, make_continuation())),
hpx::find_here(), &cb, 42);
HPX_TEST_EQ(f.get(), 87);
// The callback should have been called 4 times. wait for a short period
// of time, to allow it for it to be fully executed
hpx::this_thread::sleep_for(std::chrono::milliseconds(100));
HPX_TEST_EQ(callback_called.load(), 4);
}
// test chaining remotely, if possible
if (!localities.empty())
{
callback_called.store(0);
hpx::future<int> f = hpx::async_continue_cb(inc,
make_continuation(mult, localities[0]), localities[0], &cb, 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue_cb(inc,
make_continuation(mult, localities[0], make_continuation()),
localities[0], &cb, 42);
HPX_TEST_EQ(f.get(), 86);
f = hpx::async_continue_cb(inc,
make_continuation(mult, localities[0],
make_continuation(inc)), localities[0], &cb, 42);
HPX_TEST_EQ(f.get(), 87);
//.........这里部分代码省略.........