Skip to content

Instantly share code, notes, and snippets.

@hkaiser
Forked from NK-Nikunj/error.log
Last active July 29, 2020 00:17
Show Gist options
  • Save hkaiser/302b6eb9d688b6cc5e8dfdb26eb39171 to your computer and use it in GitHub Desktop.
Save hkaiser/302b6eb9d688b6cc5e8dfdb26eb39171 to your computer and use it in GitHub Desktop.
#include <hpx/hpx_main.hpp>
#include <hpx/hpx.hpp>
#include <cstdlib>
#include <chrono>
int universal_ans(int)
{
hpx::this_thread::sleep_for(std::chrono::seconds(5));
return 42;
}
HPX_PLAIN_ACTION(universal_ans, universal_ans_action);
template <typename Action, typename... Ts>
int invoker(Ts&&... ts)
{
hpx::thread t([&]() {Action{}.invoke(0, 0, std::forward<Ts>(ts)...);});
t.interrupt();
t.join();
return 0;
}
template <typename Action, typename... Ts>
using invoker_action =
typename hpx::actions::make_action<
decltype(&invoker<Action, Ts...>),
&invoker<Action, Ts...>
>::type;
int main()
{
invoker_action<universal_ans_action, int> ac;
hpx::future<int> f = hpx::async(ac, hpx::find_here(), 5);
f.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment