Multi threading question
If i declare a thread named th1 globally,but create it inside a For loop that run 5 times.Does the end result being 5 types of thread th1 being created?
The thread's process will be spawned 5 times, but the handle for the thread ('th1' in this case), is overwritten each time the loop is executed, so you end up with th1 being the 5th thread.
You might want to consider crating an array to store the threads, and shift the index, since you'll be counting anyway. ;)
You might want to consider crating an array to store the threads, and shift the index, since you'll be counting anyway. ;)
int numThreads = 5;<thread type> threads[numThreads];int i;for (i = 0;i < numThreads;i++){ threads = <create spawning function>;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement