Sign in to follow this  

Multithreading in game programming

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

Hi all, Just had a question about multithreading and it's uses in game programming. Is it common to use multithreading? How about some good examples? Would it be a good idea for example, to have a thread responsible for polling input devices? Thanks, Est

Share this post


Link to post
Share on other sites
in win32 you can usally just put your game loop in with the windows message loop, though for a multipler game you may want to have a seprate thread to hand network and game calculation, by seporating it from the graphics and input thread and giving it a higher priority, so if a computer is too slow it will lose frame rate but stay syncrinization with the other players and keep packets from backing up.

Share this post


Link to post
Share on other sites
I wouldn't say that it's common in my experience, but it is used.

For example, a game that I worked on for the last few years (now released and pretty much done) has the drawing and physics/input in different threads. There are a few good reasons for this. In our case, it allowed us to bypass the awkward "dead time" associated with v-sync while still avoiding tearing. Furthermore we were able to take good advantage of hyper-threading and/or multiple CPUs.

In our case it was a fairly simply change since the physics engine was also made deterministic (for replays and such). A good chunk of the code is wrapped in a critical section, but surprisingly this does very little to hinder paralellism: often the parts of the game engine that take the longest are the silly little things (drawing stars in our case) that don't even need to touch game data.

Regarding input though, you probably don't need to do that. If you're using DirectInput (or something that uses it behind the scenes, like SDL), it already spawns its own thread to poll devices, reporting all of the events when queried. Thus it'd be overkill to do that yourself.

The only thing that might be nice about it would be to keep smooth mouse movement (for example) even if the game slows down. However, it would need to be the physics slowing things down (if it's the rendering, you're not going to be able to render the cursor any faster anyways).

Anyways I'm sure others have better insights than me, but those are some of my experiences messing around with it in the past few years :) I suspect that in the future as dual-core (and more) CPUs become more common - plus with processing structures like the PS2 and Cell - things like multithreading, and potentially more importantly stream processing, will become more necessary.

Share this post


Link to post
Share on other sites

This topic is 4692 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this