Created
June 6, 2020 13:29
-
-
Save hkaiser/c1b335dc23679cb7c84fe2adbdf4cfe4 to your computer and use it in GitHub Desktop.
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_main.hpp> | |
#include <hpx/hpx.hpp> | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <atomic> | |
#include <thread> | |
class myClass | |
{ | |
private: | |
// shared by all threads; | |
static int manager; | |
public: | |
// must being able to call without creating object of myClass | |
static void init() | |
{ | |
manager=42; | |
} | |
// attachThread must be static | |
static int attachThread(int id) | |
{ | |
hpx::threads::set_thread_data(hpx::threads::get_self_id(), id); | |
std::cout | |
<< "\n thread id: "<< id << " myID: " | |
<< hpx::threads::get_thread_data(hpx::threads::get_self_id()); | |
return hpx::threads::get_thread_data(hpx::threads::get_self_id()); | |
} | |
}; | |
int myClass::manager; | |
int main() { | |
myClass::init(); | |
std::vector<hpx::thread> threads; | |
threads.reserve(3); | |
threads.emplace_back(&myClass::attachThread, 0); | |
threads.emplace_back(&myClass::attachThread, 1); | |
threads.emplace_back(&myClass::attachThread, 2); | |
for ( auto& t : threads ) | |
t.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment