Skip to main content
gamedev.net
🔒 Locked

Multi threading question

Started by Moose6912 Jan 2, 2005 at 6:20 AM 0 replies 1k views
Original Post
Moose6912
Moose6912
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?
Gorax
Gorax
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. ;)

int numThreads = 5;<thread type> threads[numThreads];int i;for (i = 0;i < numThreads;i++){  threads = <create spawning function>;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.