2

I am developing an application for Windows in which required run three processes:_thread_EEG (acquisition), _thread_MachineLearning (processing), _thread_Interface (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():

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"

What am I doing wrong?

Victor
  • 23
  • 5
  • 3
    Please extract a minimal example. Also, use C++11 threads, they integrate much better with C++ than `CreateThread()`. Also, it avoids some dangers like the lacking runtime initialization. Lastly, the difference between a plain function and a member function is explained in the C++ FAQ at parashift's. – Ulrich Eckhardt May 30 '16 at 16:24
  • Yes especially as you are using VC++ 2015. No need to rely on the dedicated windows thread implementation when you can use the portable standard version. – Dennis May 30 '16 at 16:25
  • 1
    I would highly recommend to use `std::thread` instead of the windows native functions. – πάντα ῥεῖ May 30 '16 at 16:25
  • To add up to the above, `std::thread` also makes it a lot easier to use non `static` class members as thread functions. – πάντα ῥεῖ May 30 '16 at 16:35
  • Thanks for the suggestion. Please, some reference? – Victor May 30 '16 at 17:51

1 Answers1

1

The thread function must be static, so add static before DWORD __stdcall...

Also, fourth parameter to CreateThread is the routine parameter. You are expecting pointer to uMotor, but passing &endTime instead. Replace &endTime with this.

Isso
  • 1,285
  • 11
  • 23
  • Thank you! But now I have another error: `#error directive: WINDOWS.H already included. MFC apps must not #include uMotor c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afxv_w32.h` – Victor May 30 '16 at 17:55
  • See http://stackoverflow.com/questions/1017814/error-windows-h-already-included-mfc-apps-must-not-include-windows-h, second answer – Isso May 30 '16 at 17:59
  • I've tried the solutions they suggest unsuccessfully. My application is 64 bits. That could be the problem? – Victor May 30 '16 at 18:07
  • I was wrong. The solution is to add the header ``. Thank you! – Victor May 30 '16 at 18:24