[英]Multithreading non-static in class C++
I am developing an application for Windows in which required run three processes:_thread_EEG (acquisition), _thread_MachineLearning (processing), _thread_Interface (interface).我正在为 Windows 开发一个应用程序,其中需要运行三个进程:_thread_EEG(获取)、_thread_MachineLearning(处理)、_thread_Interface(接口)。 The second process uses data by the first process, and third process requires the result of the second process.第二个进程使用第一个进程的数据,第三个进程需要第二个进程的结果。
class uMotor{
private:
long _endTime;
bool _busyBuffer;
bool _busyLabel;
Raw _Shared_buffer;
char _Shared_label ;
uEEG _gtec;
Interface _screen;
void _EEG (long endTime);
void _MachineLearning(long endTime);
void _Interface (long endTime);
DWORD __stdcall _Thread_EEG(LPVOID arg){
uMotor *yc_ptr = (uMotor*)arg;
yc_ptr->_EEG(_endTime);
return 1;
}
DWORD __stdcall _Thread_MachineLearning(LPVOID arg){
uMotor *yc_ptr = (uMotor*)arg;
yc_ptr->_MachineLearning(_endTime);
return 1;
}
DWORD __stdcall _Thread_Interface(LPVOID arg){
uMotor *yc_ptr = (uMotor*)arg;
yc_ptr->_Interface(_endTime);
return 1;
}
public:
uMotor();
void BCI();
~uMotor();
};
The threads are called in function uMotor::BCI()
:这些线程在函数uMotor::BCI()
中调用:
void uMotor::BCI(){
const long NUM_SECONDS_RUNNING = 9;
long startTime = clock();
long endTime = startTime + NUM_SECONDS_RUNNING * CLOCKS_PER_SEC;
HANDLE Handle_Thread_EEG = 0;
HANDLE Handle_Thread_MachineLearning = 0;
HANDLE Handle_Thread_Interface = 0;
Handle_Thread_EEG = CreateThread(NULL, 0, _Thread_EEG, &endTime, 0, NULL);
Handle_Thread_EEG = CreateThread(NULL, 0, _Thread_MachineLearning, &endTime, 0, NULL);
Handle_Thread_EEG = CreateThread(NULL, 0, _Thread_Interface, &endTime, 0, NULL);
}
In the function CreateThread
, Visual Studio 2015 shows an error argument of type "DWORD(_stdcall uMotor::*)(LPVOID arg)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"
在函数CreateThread
,Visual Studio 2015 显示argument of type "DWORD(_stdcall uMotor::*)(LPVOID arg)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"
的错误argument of type "DWORD(_stdcall uMotor::*)(LPVOID arg)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"
What am I doing wrong?我究竟做错了什么?
The thread function must be static, so add static
before DWORD __stdcall
...线程函数必须是静态的,所以添加static
之前DWORD __stdcall
...
Also, fourth parameter to CreateThread
is the routine parameter.此外, CreateThread
第四个参数是例程参数。 You are expecting pointer to uMotor
, but passing &endTime
instead.您期望指向uMotor
指针,而是传递&endTime
。 Replace &endTime
with this
.用this
替换&endTime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.