Jump to content
  • Advertisement
Sign in to follow this  
retroworld

SDL Threading???

This topic is 2911 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

Okay, I know SDL has a multi-threading thing to use in your application, but what if the users PC has only one processor and the application uses 3/4 thread for example.

What would happen? is there a way to know how many thread you are able to use in your application?

Also what is threading used for really? I was thinking maybe if you have a mulitplayer game, then you can open a thread for each player so that if you have a problem with one client, it doesn't effect the rest or if you have music in you application, you will be able to open a new thread for it. But what happens if you have 500+ players on your game? would the PC beable to handle that many threads?

Share this post


Link to post
Share on other sites
Advertisement
Here's a series of 30 articles on threading.

Quote:
is there a way to know how many thread you are able to use in your application?
You can use as many as you want, but if you have many more than there are processors to execute them, then you're going to cause the OS to constantly swap them in/out of the CPU, which has a performance cost.
There are windows functions (and equivalents on other OSs) that tell you how many CPU cores the user's computer has, which you can use to influence your decision of how many to use.
Quote:
Also what is threading used for really?
1) To allow an application to remain responsive while completing a large task (e.g. creating/loading content in the background while the game is being played, to avoid loading screens).

2) To spread computation over multiple CPUs/Cores. CPUs used to get faster and faster every year, making our games run better on new computers. These days, they're getting more and more concurrent instead, which means if you want you game to keep getting better performance out of newer and newer computers, it has to be able to split it's work over as many CPUs as possible.
Quote:
I was thinking maybe if you have a mulitplayer game, then you can open a thread for each player ... But what happens if you have 500+ players on your game?
Exactly - that's a really bad idea. Instead you could make a thread-pool with one thread per CPU core, then you could divide the players by the number of threads in the pool, and distribute large groups of players to each thread.
Quote:
or if you have music in you application, you will be able to open a new thread for it
This is a decent idea - most sound libraries do this, because you need to make sure that the sound-buffers are constantly fed with data from the disk (even if the game is running at a very low frame-rate) - i.e. sound has to be more responsive than the main thread.

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!