我的帖子停止了

时间:2015-06-22 16:42:22

标签: c++ multithreading matrix

我的问题是我正在启动一个Thread来从我的EyeTracker中读取数据。我使用以下函数启动它:

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,在我的类的头文件中被定义为私有的volatile布尔值:

class BlinkMode
{

private:

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

在创建Matrix实例后立即变为假,(Matrix是我的代码的另一类)。因此,永远不会输入while循环。但是,如果我对Matrix线进行评论,它就可以了!我甚至可以执行新的float“recordeddata”,但不能执行Matrices。

这是否意味着当我在Thread内部时,我无法调用另一个类?对不起,我对C ++很新,我迷路了。

请帮忙吗?

提前致谢!

1 个答案:

答案 0 :(得分: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

所以我只是在那里创建了两个对象,那就是当布尔值自动变为false时! 我刚刚创建了你提到的pThis指针,它能够访问布尔值并检查它何时发生变化,但它与代码无关......我可以擦除它并且没有任何变化......