2015-06-22 98 views
0

我的问题是,我开始一个线程从我的眼球追踪系统中读取数据。我开始使用它了以下功能:我的线程停止

BlinkMode::BlinkMode() 
{ 
bBlink = false; 
threadStopped = true; 

recordeddata = nullptr; 

gT = GazeTracker::getGazeTracker(); 
canRecord = false; 
numCameras = gT->getNumCameras(); 
if(numCameras >0){ 
    canRecord = true; 
} 

filename = "blinkmode.txt"; 
counter = 0; 
calipointno = 0 ; 
} 

void BlinkMode::startRecording() 
{ 
if (!bBlink) 
{ 
    // Turn thread loop signal on 
    bBlink = true; 
    bBlinkSuccess = false; 
    bExcessData = false;  
    blinkThread = std::thread(createBlinkThread, this); 
} 
} 

void BlinkMode::createBlinkThread(void* instance) 
{ 
    BlinkMode* pThis = (BlinkMode*) instance; 
    pThis->bBlink; 
    if(pThis->canRecord){ 
    pThis->threadStopped = false; 
    pThis->BlinkModeThread(); 
    pThis->threadStopped = true; 
} 
} 

void BlinkMode::BlinkModeThread() 
{ 
BlinkMode* pThis = (BlinkMode*) this; 
pThis->bBlink; 

Matrix mProvData = Matrix (DR_DATAANALYSIS, GT_EYEDATALENGTH); 
Matrix aSourceMatrix = Matrix (DR_MAXRECORDEDDATA, GT_EYEDATALENGTH); 
recordeddata = new float[DR_MAXRECORDEDDATA][GT_EYEDATALENGTH]; 


while(bBlink){ 

    if(counter<DR_MAXRECORDEDDATA){ 
     gT->getCurrentData(recordeddata[counter],ALLDATA); 

[ETC ...]

的事情是,我的布尔bBlink,它被定义为班里的头文件中的私人挥发性布尔:

class BlinkMode 
{ 

private: 

// Monitor thread control signal. 
volatile bool bBlink;} 

在Matrix实例创建后(Matrix是我的代码的另一类)就变成了错误。因此,while循环从不输入。但是,如果我评论矩阵线,它的工作原理!我甚至可以执行新的float“recordingdata”,但不是矩阵。

这是否意味着我无法在线程或其他东西中调用其他类?对不起,我用C++很新,而且我迷路了。

请帮忙吗?

在此先感谢!

+0

也许您还应该提供Matrix功能的代码。我也不明白'BlinkMode * pThis =(BlinkMode *)这个意义是什么; pThis-> bBlink;'在这里......你可能是未定义行为的受害者 – Vinzenz

回答

0

Matrix类只是初始化以不同的方式矩阵,做业务与他们有点像这样:

class Matrix 
{ 
public: 
// Default constructor 
Matrix(); 
// Default destructor 
~Matrix(); 
// Initialise matrix of rows x cols. 
Matrix(const int rows, const int cols); 
// Convert a two dimensional array (rows x cols) of integers to a matrix. 
Matrix(const int* const* num, const int rows, const int cols); 
// Convert a two dimensional array (rows x cols) of floats to a matrix. 
Matrix(const float* const* num, const int rows, const int cols); 
// Copies the required row into the array. 
void getRow(const int row, double[]) const; 
// Copies the required row into the matrix. 
void getRow(const int row, Matrix&) const; 
// Sets the values of a row to the values of the array. 
void setRow(const int row, const int[]); 
enter code here 

所以我只是创造2个物体存在,那就是当布尔自动改变假! 我刚刚创建了pThis指针,您提到可以访问布尔值并检查它何时更改,但它与代码无关......我可以将其删除并且没有任何更改...