lundi 2 mars 2015

pass member functions of a class with constructors to std::thread

I've defined a function in a class that takes a series of constructors and am trying to pass a function (fillgamma) to std::thread. the constructors themselves are quite large so I can't really pass them as parameters to the function every time I want to use it. I get a C3867 error when I try to compile which I'm pretty certain is due to the line marked bad line.


my project has gotten quite big so I've left off a load of the peripheral stuff but here's the class definition:



class gamma_threads
{
public:
void fillgamma(int t, float &total);

gamma_threads(std::vector<float> delpro, float Stau,float gamma0, int N);
~gamma_threads();

private:
std::vector<float> delpro;
const float Stau, gamma0;
float gint=0;
const int N;

};


And here's the body of the code attempting to implement the thread:



gamma_threads T(delpro, Stau, gammafbb[0], N); // vector, float, float, int

while (flag==1)
{
std::thread th[8];
for (int i = 0; i < 8; i++)
{
if (!tlist.empty()) //tlist is a queue where I store the values to be fed to the threads
{
int temp_t = tlist.front();

th[i] = std::thread((T.fillgamma, temp_t, gammafbb[temp_t])); // bad line
if (temp_t + 8 <= tmax){ tlist.push(temp_t + 8); }
else { flag == 0; }
}
}
for (int i = 0; i < 8; i++)
{
th[i].join();
}
}


sorry if the code itself is offensively inefficient/ugly it's my first time with C++ so any other constructive criticism would be welcome too


Aucun commentaire:

Enregistrer un commentaire