jeudi 18 novembre 2021

How to pass the target function of std::thread constructor as an argument

I can do this to start my thread:

int main_test() {
  // do something...
  return 0;
}

std::thread myThread;

void myFunction() {
  myThread = new std::thread(main_test);
}

How do I pass main_test as an argument to myFunction, so the same function can be used to start the thread using different target functions? What would the identity of myFunction be then?

I guess what I don't understand is how the templated version of the std::thread constructor is invoked with a specified type.

Aucun commentaire:

Enregistrer un commentaire