I'm trying to make a multithreaded initialization routine that is going to divvy up the task based on the number of concurentThreadsSupported. It's a constructor calling another member function, but no matter how I seem to format it, I can't seem to call the other member function as a thread function. So how would I go about properly threading a member function, with arguments, from inside a class?
And before it's asked, I'm not using "using namespace std;", instead, I'm using "using std::vector;" and others as required.
Universe::Universe(const unsigned __int16 & NumberOfStars, const UniverseType & Type, const UniverseAge & Age)
{
thread *t = new thread[concurentThreadsSupported-1];
for (unsigned __int32 i = concurentThreadsSupported - 1; i > 0; i--)
{
//problem line
t[i] = thread(&Universe::System_Spawner, i, NumberOfStars / concurentThreadsSupported, Type, Age);
}
for (int i = concurentThreadsSupported - 1; i > 0; i--)
{
t[i].join();
cout << "Thread joined" << endl;
}
delete[] t;
}
void Universe::System_Spawner(const unsigned __int16 threadNumber,
const unsigned __int16 NumberOfStars, const UniverseType & Type, const UniverseAge & Age)
{
cout << "Inside Thread" << endl;
}
The error that I get is
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): error C2672: 'std::invoke': no matching overloaded function found
...
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: With the following template arguments:
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: '_Callable=void (__cdecl Universe::* )(unsigned short,unsigned short,const UniverseType &,const UniverseAge &)'
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: '_Types={unsigned int, unsigned int, UniverseType, UniverseAge}'
Aucun commentaire:
Enregistrer un commentaire