Affichage des articles dont le libellé est create threaded class functions with arguments inside class. Afficher tous les articles
Affichage des articles dont le libellé est create threaded class functions with arguments inside class. Afficher tous les articles

mardi 14 février 2017

create threaded class functions with arguments inside class

Vote count: 0

I have an object of class AI, which has a private non static void function which has a lot of arguments: minmax(double& val,double alpha, double beta, unsigned short depth, board* thisTurn); because this is a very time intensive function I want to use a number of threads to run it concurrently, therefor I must create a thread with this function inside another function inside the AI class;

According toThis question to make threads inside member functions containing non static member functions wiht no arguments of said class, one must call:

std::thread t(&myclass::myfunc,this);

And according to this tutorial threads of fucntions with multiple arguments can be created as such:

std::thread t(foo,4,5) 

where the function 'foo' has 2 integer arguments

However I desire to mix these to things, to call a function which has arguments, which is also a non static member function, from inside the class that it is a member of, and i am not sure how to mix these to things.

I have off course tried (remember that it is inside a function inside the AI class):

std::thread t(&AI::minmax,val,alpha,beta,depth,thisTurn,,this);

and

std::thread t(&AI::minmax,this,val,alpha,beta,depth,thisTurn,this);

But both cases fails with a compile error like this:

error: no matching constructor for initialization of 'std::thread'
candidate constructor template not viable: requires single argument '__f', but
  7 arguments were provided

My question is therefor, if or if not, it is even possiple to -- from inside a member function of a class -- call a non static member function which has several arguments as a thread, and if this is the case, how it is done.

asked 11 secs ago

Let's block ads! (Why?)



create threaded class functions with arguments inside class