C++ 我的线停了
我的问题是,我正在启动一个线程从我的眼动跟踪器读取数据。我使用以下功能启动它:C++ 我的线停了,c++,multithreading,matrix,C++,Multithreading,Matrix,我的问题是,我正在启动一个线程从我的眼动跟踪器读取数据。我使用以下功能启动它: BlinkMode::BlinkMode() { bBlink = false; threadStopped = true; recordeddata = nullptr; gT = GazeTracker::getGazeTracker(); canRecord = false; numCameras = gT->getNumCameras(); if( numCameras >
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);
在创建矩阵实例后立即变为false(矩阵是我代码的另一个类)。因此,永远不会进入while循环。但是,如果我对矩阵行进行注释,它是有效的!我甚至可以执行新的浮点“recordeddata”,但不能执行矩阵
这是不是意味着当我在线程或其他东西中时不能调用其他类?对不起,我是新的C++,我迷路了。
有什么帮助吗
提前谢谢 矩阵类只是以不同的方式初始化矩阵并对其进行操作,有点像这样:
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->bBlink代码>在这里。。。你可能是这里未定义行为的受害者
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