2015-06-22 75 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指針,您提到可以訪問布爾值並檢查它何時更改,但它與代碼無關......我可以將其刪除並且沒有任何更改...