Results 1 to 6 of 6
  1. #1
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default What is an acceptable amount of threads to be running at one time?

    I was just thinking. In game like, say StarCraft II, there could be 150 different units in the game at once, including all the "doodads". Is that 1 thread per unit? 1 thread per aspect of unit? (Like, 1 controlling the animation, one controlling the pathing, one controlling the lighting, etc.)

    So I guess my question is, what is an acceptable amount of threads to be running at one time? I saw somewhere 1 per core, but that seems way to low to me, considering I have at least 100 running at one time, because I currently have 1 thread running on each of my units. (To control the animation. Actually 2, because there is one waiting for any movement commands from either the AI or the user)

    So yeah, what is the "acceptable" amount of threads? And please don't say "as many as you need", because I don't know how many I need :P

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: What is an acceptable amount of threads to be running at one time?

    It's really dependent on what you need, but as you said; it's generally good to have 1 per core or #cpu+1. You want enough threads so they are getting equal time running, with threading you will have the os slicing the time for different threads to hop in an out. So increasing to 100 threads won't be very effective, a lot of threads means they will be waiting a long time to get it's turn. Threading doesn't magically make everything run at the same time, it allows a few simultaneous things, but not infinite. If you have one thread per core, they will generally always have work, and the threads can take turns performing actions.

  3. #3
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: What is an acceptable amount of threads to be running at one time?

    So how does that work then, something like the StarCraft II system? How could they have all of those units working at the same time with only 2 threads? (The amount of processors Starcraft is optimized for)

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: What is an acceptable amount of threads to be running at one time?

    I can't say for sure since I don't know what the code looks like, and have never done something as sophisticated as Starcraft. I'd imagine there are threads which control the groups of characters, and the thread switching jumps between the groups moving all the units. Modern CPU's operate extremely quick and it leads to you not seeing the pauses in between one thread and another working. Like I said; this is speculation, and there are others her with much more experience than me that may have more sound explanations of how something like this works.

  5. #5
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: What is an acceptable amount of threads to be running at one time?

    Wait, by "1 thread", do you mean 1 type of thread? Because I have a thread that updates every single unit. It is a single thread class, but there are multiple instances of it running at once. Is that okay, or should there only be 1 thread controlling all of them?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: What is an acceptable amount of threads to be running at one time?

    Something like Starcraft would probably have something like a fixed thread pool which gets runnables passed into it.

Similar Threads

  1. Problem running many Threads !!
    By AlQassabi in forum Threads and Synchronization
    Replies: 10
    Last Post: 03-04-2011, 10:29 AM
  2. Question about running Multiple Threads
    By ferdzz in forum New To Java
    Replies: 2
    Last Post: 06-29-2010, 01:19 PM
  3. keep child threads running after parent thread dies
    By adammyth in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-27-2010, 01:43 PM
  4. Running thread a second time
    By Fleur in forum New To Java
    Replies: 18
    Last Post: 11-17-2009, 12:57 PM
  5. Calculating the Running time
    By JordashTalon in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 10:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •