I am trying to declare C++11 thread as a class member, so that I can "assign" the function to begin execution, say in the constructor and I can join the thread in the destructor.
How would I go about this? I have declared the threads as members, but I am struggling with assigning the function for the thread to invoke?
Pseudo:
class X{
public:
X(){
t1(&X::func, this);
t2(&X::func, this);
}
~X(){
t1.join();
t2.join();
}
void func(){
//Does stuff
}
std::thread t1;
std::thread t2;
};
Aucun commentaire:
Enregistrer un commentaire