Created
March 14, 2018 18:04
-
-
Save NK-Nikunj/6dfd6bdb18b02645c44eb79c96524f3b to your computer and use it in GitHub Desktop.
Running main on an hpx thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hpx/hpx.hpp> | |
#include <hpx/hpx_init.hpp> | |
#include <stdlib.h> | |
int __argc = 0; | |
char** __argv = nullptr; | |
void set_argc_argv(int argc, char* argv[], char* env[]) | |
{ | |
__argc = argc; | |
__argv = argv; | |
} | |
__attribute__((section(".preinit_array"))) | |
void (*set_global_argc_argv)(int, char*[], char*[]) = &set_argc_argv; | |
int main(int argc, char* argv[]); | |
struct manage_global_runtime { | |
manage_global_runtime() { | |
std::cout << "calling from struct" << std::endl; | |
hpx::init(main, __argc, __argv); | |
std::cout << "back in struct" << std::endl; | |
exit(1); | |
} | |
}; | |
manage_global_runtime init; | |
int universal_ans(){ | |
return 42; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
std::cout << "Hello World!" << std::endl; | |
hpx::future<int> f = hpx::async(universal_ans); | |
int ans = f.get(); | |
std::cout << ans << std::endl; | |
return hpx::finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment