The program will use an amount of threads equal to the amount of cores in a system(I know how to find this), and the threads need to be able to access the variables that I had before trying to convert it to use multithreading.
I am using C++, windows.h, and microsoft VC++ 2008 express.
Here is the part of the program I'm having problems with:
in Object.h I have:
#ifndef OBJECT_H
#define OBJECT_H
#include <vector>
#include <windows.h>
#include "math.h"
#include "DarkGDK.h"
using namespace std;
class Object
{
private:
DWORD WINAPI mainThread(LPVOID lpParam);
int numCores; //number of available cores on CPUs.
void bufferObjects();
};
#endif
and in Object.cpp i have:
void Object::bufferObjects()
{
HANDLE *Array_Of_Thread_Handles = NULL;
Array_Of_Thread_Handles = new HANDLE[numCores];
for(int i = 0; i < numCores; i++)
{
Array_Of_Thread_Handles[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mainThread, (LPVOID)i, 0, NULL);
//SetThreadAffinityMask(Array_Of_Thread_Handles[i], m_mask);
}
WaitForMultipleObjects(numCores, Array_Of_Thread_Handles, TRUE, INFINITE);
for(int i = 0; i<numCores; i++)
{
CloseHandle(Array_Of_Thread_Handles[i]);
}
}
I am getting the error:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'
None of the functions with this name in scope match the target type
I have gotten rid of this error by making the thread function static, but then the thread cannot access the variables of the Object.h class because it wants them to be "static" too, and I am not very familiar with static functions.

New Topic/Question
Reply




MultiQuote





|