I am instantiating multiple instance of a class that creates a thread. Since threads are static, will the instances of the object interfere with each other’s thread operation?
Oddly I see 2 different waveforms and running at two different Sleep delays. ??? so does this mean there are 2 different threads ???
void CWaveGeneration::CreateWave()
{
Y = new double[numPoints];
X = new double[numPoints];
I = new int[numPoints];
CWaveGeneration *pp = this;
hThread_Wave = CreateThread(NULL, 0, Thread_Wave, pp, 0, NULL);
//within the thread, there is the setting of Sleep(iSleep);
}
void CWaveGeneration::CreateWave(int _waveType, double _A, double _w, double _T, double _r, int _numPoints, int _iSleep)
{
waveType = _waveType;
A = _A;
w = _w;
T = _T;
r = _r;
numPoints = _numPoints;
iSleep = _iSleep;
CreateWave();
}
DWORD WINAPI CWaveGeneration::Thread_Wave(LPVOID iValue)
{
CWaveGeneration *p = (CWaveGeneration*)iValue;
switch (p->waveType)
{
case 0:
p->Sine();
break;
case 1:
p->Square();
break;
case 2:
// p->Triangle();
break;
case 3:
// p->SawTooth();
break;
}
return true;
}
from the header file:
static DWORD WINAPI Thread_Wave(LPVOID iValue);
wave1 = new CWaveGeneration();
wave1->CreateWave(0,100,10,0,0,200, 10);
wave2 = new CWaveGeneration();
wave2->CreateWave(1,80,5,0,0,200, 100);
// in total, are there 1 thread or 2 threads created here ???
If the thread object in your class is static, then you will have only one thread for all the instances of the class.
If the thread object in the class is not static, then each instance of the class will have 1 thread object.This should not have any problem.