-
December 4th, 2007, 01:23 AM
#1
how to create thread in c++
hai friends
i want a simple program it must contain only one method. when i call the method it invoke. please give me small thread program in c++ with thread.
-
December 4th, 2007, 04:34 AM
#2
Re: how to create thread in c++
-
December 4th, 2007, 04:46 AM
#3
Re: how to create thread in c++
-
December 4th, 2007, 08:24 AM
#4
Re: how to create thread in c++
You need at least two functions----a main function, and a function to be run in the new thread.
If you choose to use pthread_create() to make your thread, the function which will run in it must have the prototype
Code:
void* threadmain(void *args);
Where you can make threadmain and args be whatever strings you prefer.
-
December 5th, 2007, 12:46 AM
#5
Re: how to create thread in c++
DWORD WINAPI runThread(LPVOID args)
{
int* value = reinterpret_cast<int*>(args);
printf("\n in thread %d", *value);
}
int main()
{
DWORD threadId;
int value = 10;
hThread = CreateThread( NULL, 0, runThread, &value, 0, &threadId);
return 0;
}
you can use waitforsingleobject() to check the thread status whether is has exited normally or with any error.
For more details please look into MSDN for each of the API
Hope this will help you
-
December 5th, 2007, 04:51 AM
#6
Re: how to create thread in c++
Check out the Simple Thread: Part I article - it shows how to start, pause, resume, stop and cleanup a thread..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|