Jump to content
  • Advertisement
Sign in to follow this  
Moose6912

Multi threading question

This topic is 4890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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>;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!