|
-
August 11th, 2010, 03:06 AM
#1
Spawn multiple THREADS simultaneously
Pls refer to the below Win32 code:
Code:
#define THREADCOUNT 4
int main()
{
DWORD IDThread;
HANDLE hThread[THREADCOUNT]; //Handle maximum of 4 threads
int i;
// Create multiple threads.
for (i = 0; i < THREADCOUNT; i++)
{
hThread[i] = CreateThread(NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE) ThreadFunc, // thread function
NULL, // no thread function argument
0, // use default creation flags
&IDThread); // returns thread identifier
// Check the return value for success.
if (hThread[i] == NULL)
ErrorExit("CreateThread error\n");
}
for (i = 0; i < THREADCOUNT; i++)
WaitForSingleObject(hThread[i], INFINITE);
return 0;
}
Here I can create 4 threads simultaneously, but to my knowledge the thread controlling function ("ThreadFunc") will be common to all the 4 threads. Now if one of the 4 threads becomes signaled (for example), then how do I process it inside the ("ThreadFunc") ?
Thanks,
-
August 11th, 2010, 03:22 AM
#2
Re: Spawn multiple THREADS simultaneously
Every thread has its own stack memory, and thus, its own local variables. So despite the fact that the thread procedure code is the same, every thread lives its own life.
Best regards,
Igor
-
August 11th, 2010, 03:40 AM
#3
Re: Spawn multiple THREADS simultaneously
Thanks for the reply.
What I am unable to figure out is that after the thread creation, what source code should be used inside the thread control function, for a particular thread getting signaled?
For example, if thread #3 was blocked earlier, and now gets signaled, what code should I use in the common thread control function to process thread #3?
Thanks,
-
August 11th, 2010, 01:41 PM
#4
Re: Spawn multiple THREADS simultaneously
Frankly, I have no idea what you're talking about. "Blocked", "signaled", "to process"? All this sounds either ambiguous or senseless. Blocked which way? To process thread, what would that mean? Signaled thread? Thread object gets signaled right after thread execution was finished. Now you see? You have to come up with somewhat better explanation of what you want.
Best regards,
Igor
-
August 12th, 2010, 12:17 AM
#5
Re: Spawn multiple THREADS simultaneously
hi,
every thread has its own stack memory, and thus, its own local variables. So despite the fact that the thread procedure code is the same, every thread lives its own life.To process thread, what would that mean? Signaled thread? Thread object gets signaled right after thread execution was finished.
thanks
regards,
phe9oxis,
http://www.guidebuddha.com
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
|