0

Hi,
I am having a problem in implementing multithreading in my program.i have a function which goes like this
int x=NodesArray[2]->SendData(routeInfo,countDataPackets,pathInf);

i want to call this function with the help of CreateThread
and i did it this way

hThread[0]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)NodesArray[2]->SendData(routeInfo,countDataPackets,pathInf),NULL,0,&dwID);
i just read some programs online and read microsoft visual c++ implementation of creation of threads.I know that the createthread returns a dword value..i couldnt really understand what this dword means and i want to know how i can send multiple parameters using createthread function as you can see my SendData function is using three parameters.could any suggest me how to go about this procedure..thanks in advance...

2
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by jimmy.rocks1
0

First, the new thread must be either a static class method of a simple function. A DWORD is just an unsigned long, but don't count on that being the case in all versions of Windows.

To pass multiple parameters, create a structure with all the variables you want to pass and pass a pointer to that object in CreateThread.

0

thank you for replying
i have two questions on your reply i am writing my code in visuall c++ 6 and it is saying that create thread is returning a void * . i came to know about this when i tried to typecast it to integer.

and also you have told that to pass multiple parameters i need to create a structure and put all my variables in it and pass the object of that structure.can i not do by declaring a class and putting those variables in the class and creating a class object and passing that object as parameter..

thanks

0

>>create thread is returning a void *
It actually returns a HANDLE, which is probably a void*. As long as hThread[0] is a HANDLE your code should be ok.

For your 2nd question, yes you can pass a pointer to a class object. just typecast it to void*

0

Hi thank you for replying..

could you tell me how to actually declare a class method as thread
for example:-

class X{
int method m1;
}
int X::method m1{
cout<< i m in method 1;
}
how can i declare a method m1 as thread

becoz in the examples that i have seen i could see the declaration as

DWORD WINAPI mythread(LPVOID lparam){
}

i couldnt find any example for the above case...coudl you give me any example of that kind
thanks

0
class X{
public:
    X() {m1 = 0;}
    static DWORD WINAPI mythread(LPVOID lparam);
protected:
int method m1;
};

Since mythread() is a static member of that class you can pass it to CreateThread as the thread function.

0

Hi ,
i could actually create the thread but what if i want to terminate a thread.....i found that there is function SuspendThread(threadHandle)...but i could even see in the microsoft documentation that the function has been truncated ...is there any other way that i could suspend a thread, thanks in advance.....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.