I have three classes:
class Rtss_Generator {
int mv_transfersize;
}
class Rtss_GenSine : Rtss_Generator
class Rtss_GenSineRpm : Rtss_GenSine
Rtss_GenSine creates a stream in its constructor, it starts immediately and the stream function is disabled, the static stage is waiting for the event to be evaluated.
problem: all variables accessed through the pointer gene are 0, but this will not work. In addition, this address in the constructor and the gene-pointer-address in the stream are the same, so the pointer is fine.
this code is generated and compiled in the Visual Studio 6.0 2003 Service Pack
ORIGINAL CODE
no thread
Rtss_GenSine::getNextData() {
//[CALCULATION]
//mv_transferSize is accessible and has ALWAYS value 1600 which is ok
}
NEW CODE
Rtss_GenSine::Rtss_GenSine() {
createThread(NULL, threadFunction, (LPVOID) this,0,0);
}
Rtss_GenSine::getNextData() {
SetEvent(startCalculating);
WaitForSingleObject(stoppedCalculaing, INFINITE);
}
DWORD Rtss_GenSine::threadFunction(LPVOID pParam) {
Rtss_GenSine* gen = (Rtss_GenSine*) pParam;
while(runThread) {
WaitForSingleObject(startCalculating, INFINITE);
ResetEvent(startCalculating)
setEvent(stoppedCalculaing)
}
}
source
share