class C++ 中的多线程非静态

Multithreading non-static in class C++

我正在为 Windows 开发一个应用程序,其中需要 运行 三个 processes:_thread_EEG(获取)、_thread_MachineLearning(处理)、_thread_Interface(接口) ).第二个进程使用第一个进程的数据,第三个进程需要第二个进程的结果。

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();
};

线程在函数中调用 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);
}

在函数CreateThread中,Visual Studio2015显示错误argument of type "DWORD(_stdcall uMotor::*)(LPVOID arg)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"

我做错了什么?

线程函数必须是静态的,所以在DWORD __stdcall之前加上static...

另外,CreateThread的第四个参数是常规参数。您期待指向 uMotor 的指针,但传递的却是 &endTime。将 &endTime 替换为 this.