//function creating my class and thread
extractor = new FeatureExtractor(receiveBufferCurrent);
HANDLE hth1;
unsigned uiThread1ID;
hth1 = (HANDLE)_beginthreadex(NULL,
0,
FeatureExtractor::ThreadStaticEntryPoint,
extractor,
CREATE_SUSPENDED,
&uiThread1ID);
//Header file
class FeatureExtractor
{
private:
float sensorData[200][10];
public:
FeatureExtractor(float receiveBufferCurrent[][10]);
~FeatureExtractor();
//Thread for parallel input and motion detection
static unsigned int __stdcall ThreadStaticEntryPoint(void * pThis);
void ThreadEntryPoint();
void outputTest();
};
FeatureExtractor::FeatureExtractor(float receiveBufferCurrent[][10])
{
memcpy(sensorData, receiveBufferCurrent, sizeof(sensorData));
}
unsigned __stdcall FeatureExtractor::ThreadStaticEntryPoint(void * pThis)
{
FeatureExtractor * pthX = (FeatureExtractor*)pThis;
pthX->ThreadEntryPoint();
return 1;
}
void FeatureExtractor::ThreadEntryPoint()
{
outputTest();
}
//output function
for (int i = 0; i < 200; i = i + 50)
{
std::cout << "-------------------------------------------------------------------------" << std::endl;
std::cout << "AccelX=" << sensorData[i][1] << ", AccelY=" << sensorData[i][2] << ", AccelZ=" << sensorData[i][3] << std::endl;
std::cout << std::endl;
std::cout << "MagX=" << sensorData[i][4] << ", MagY=" << sensorData[i][5] << ", MagZ=" << sensorData[i][6] << std::endl;
std::cout << std::endl;
std::cout << "GyroX=" << sensorData[i][7] << ", GyroY=" << sensorData[i][8] << ", GyroZ=" << sensorData[i][9] << std::endl;
std::cout << std::endl;
std::cout << "-------------------------------------------------------------------------" << std::endl;
}
我在访问线程内的float数组“sensorData”时遇到了一些问题。 如果我在构造函数中输出sensorData数组一切都很好但是如果我从我的线程内部访问数组我的数组只包含-1.58839967e + 038,我想这意味着我无法以这种方式从一个线程访问我的数组。
我做错了什么?
我从教程中获得了线程代码,该教程以相同的方式访问类成员变量,尽管只是整数而不是多维数组。
我尽量减少代码片段的长度,同时保留重要部分,我很感谢任何人花时间分析我的代码!
答案 0 :(得分:0)
我现在自己找到了解决方案。
{{1}}
等待我的帖子后,问题就解决了。 之所以出现这个问题是因为我在完成执行之前删除了我的类。 它还可以简单地删除删除语句。