Click to See Complete Forum and Search --> : Spawn multiple THREADS simultaneously


xmarshall
August 11th, 2010, 03:06 AM
Pls refer to the below Win32 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,

Igor Vartanov
August 11th, 2010, 03:22 AM
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.

xmarshall
August 11th, 2010, 03:40 AM
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,

Igor Vartanov
August 11th, 2010, 01:41 PM
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.

mani3355
August 12th, 2010, 12:17 AM
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