C ++ is like a stream parameter, variables are not available

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)

        //[CALCULATION]
        //gen->mv_transferSize ---> it does not fail, but is always zero
        //all variables accessed via the gen-pointer are 0

        setEvent(stoppedCalculaing)
    }
}
+3
source share
2 answers

Perhaps you are doing something like this:

Rtss_GenSize someFunc()
{
   Rtss_GenSize temp;
   return temp;
}

Rtss_GenSine mygensize = some_func();

, , mygensize (), 'this' , .

... , Rtss_GenSine, , ...

+2

- , startCalculating mutex, , mv_transferSize , getNextData...

0

Source: https://habr.com/ru/post/1745167/


All Articles