0

As the title suggests, I am unable to implement multi-threading from within a member method referring to two private methods of the class. How I understood the problem initially is that as an instance does not exist the CreateThread function would not have a function reference till an object was created, to overcome that problem I used 'this' keyword to reference the method in the CreateThread function and I'm getting the following two errors:
1. error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'
2. error C2660: 'CreateThread' : function does not take 5 arguments

class DirectoryParser {
public:

    //Default Constructor
    DirectoryParser() {

    }

    //Parameterised Constructor
    DirectoryParser(string inDirPath, string outDirPath)  {
        _inDirPath = inDirPath;
        _outDirPath = outDirPath;
    }

    //Destructor
    ~DirectoryParser() {

    }

    //Public Methods

    int SearchDirectory();

private:

    //Data Members

    string _inDirPath;
    string _outDirPath;
    vector<string> _zipFiles;

    //Private Methods

    void SearchCurrent();

    void SearchZip();
};

The function where I'm trying to implement the threading.

int DirectoryParser::SearchDirectory() {

    //Thread Creation
    t[0] = CreateThread(
        NULL,
        0,
        (LPTHREAD_START_ROUTINE)this->SearchCurrent,
        NULL,
        0,
        &threadID);
    t[1] = CreateThread(
        NULL,
        0,
        (LPTHREAD_START_ROUTINE)this->SearchZip,
        NULL,
        0,
        &threadID);

    //Check for completion of a thread
    WaitForMultipleObjects(
        2,
        t,
        TRUE,
        INFINITE);
    CloseHandle(t);
}

I am sorry if this question was already asked, but I searched and couldn't find it. Also I'm just starting to learn multi-threading, so go easy on me. :D

A similar question that was asked, but he was passing 'this' itself as a parameter to the method.

EDIT: Well I don't see how the link that @Bo Persson marked is similar to my question in any way. I would suggest please read my question through. If I'm still wrong please let me know how

Community
  • 1
  • 1
  • Use `std::thread` if you want to use a non-static member function. – Jonathan Potter Sep 27 '16 at 08:37
  • @JonathanPotter thanks a lot. I was just curious as to why this isn't working, and also was hoping for a way to make this code work. Hopefully you or someone else could help me out in understanding the issue. – Siddharth Gupta Sep 27 '16 at 09:06

0 Answers0