Hi all , I am having problem about killing multiple treads in my program at the same time, here is my code:
int main()
{
while(1)
{
i++;
HANDLE thread =(HANDLE)_beginthread(TheThread, 0, NULL);
if(i==10)
break;
}
Sleep(3000);
TerminateThread(thread,0);
return 0;
}
now "TerminateThread(thread,0);" will only terminate the 10th thread , but how i will be able to terminate the 10 threads at once, also i don't want to create a new variable for new threads and terminate them like:
HANDLE a,b,c;
a =(HANDLE)_beginthread(TheThread, 0, NULL);
b =(HANDLE)_beginthread(TheThread2, 0, NULL);
c =(HANDLE)_beginthread(TheThread3, 0, NULL);
Sleep(3000);
TerminateThread(a,0);
TerminateThread(b,0);
TerminateThread(c,0);
as it will be hard to write the program if i want to create 300 threads at once, so please help me :(
Thanks in advance