| | |
multithreading c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 12
Reputation:
Solved Threads: 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]);
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...
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]);
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...
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.
To pass multiple parameters, create a structure with all the variables you want to pass and pass a pointer to that object in CreateThread.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Dec 2007
Posts: 12
Reputation:
Solved Threads: 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
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
>>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*
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*
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Dec 2007
Posts: 12
Reputation:
Solved Threads: 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
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
C++ Syntax (Toggle Plain Text)
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Dec 2007
Posts: 12
Reputation:
Solved Threads: 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.....
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.....
![]() |
Similar Threads
- Help in Multithreading. (C++)
- Need Help Regarding MultiThreading (ASP.NET)
- multithreading & destructor call. (C++)
- Multithreading in C++ (C++)
- c# multithreading help needed ---urgent (C#)
- java multithreading (Java)
- Multithreading error (C++)
- Ruby multithreading (Ruby)
- Multithreading problem (C)
Other Threads in the C++ Forum
- Previous Thread: Username/PW entry help
- Next Thread: compiler vs ide , is there a difference ?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






