vendredi 3 avril 2015

Create instance of a class in a separate thread using CreateThread method in windows c/c++

I am new to c/c++ and multithreading... I would like to know how to create an instance of a class in a separate thread every time and work parallel



class ThreadedClass
{
bool open(const char* Name);
bool write(char* buffer, int size);
bool read(char* buffer, int size);
};


I have method "Open" with some parameter name ie open("name1"); which is internally creating separate thread for read() member.



int NewThreadedfunction(const char* name)
{
ThreadedClass Instance = new ThreadedClass();
Instance.open(name);
}


so when ever I call NewThreadedfunction with name it should create a new instance in a separate thread ie calling



NewThreadedfunction("name1");
NewThreadedfunction("name2");


now whole class methods should run in separate thread with instance "name1" also whole class methods should run in separate thread with instance "name2" so that both are running in parallel.


Aucun commentaire:

Enregistrer un commentaire