# When should new threads be created in a game or how should time consuming task be handled?

This has been a question that has always troubled me while thinking about the code and logic behind gaming, I was wondering when and when not, is it appropriate to create new threads for different tasks or how should I handle long tasks that could potentially freeze my game?

The first situation I could think of would be the rendering and the update loop. My thought behind this is that keeping these two seperate would prevent update problems because of a low frame-rate so even if the frame rate is changed there would still be a consistent update cycle.

The second situation is somewhat more specific and is just an example but say my game has multiple building components that can be placed over the world and my game updates them every second or so to check maybe if they are floating (if they have physics) or maybe if it's environment has changed, should this update cycle also be in another thread because it could take a long time?

How about if I was pinging a client, would my server not freeze whilst waiting for a response? Is this another situation where threads should be created? or is there another technique that I should be using to enhance performance and efficiancy?

• Well first, games very rarely do something that wpuld freeze them other than pinging and such. Networking, physics and rendering should have it's own thread. Dec 6 '16 at 7:52
• Instead of threading Draw() vs Update(), you can just add some logic to skip draw calls. So your Update() runs at 60fps all the time, Draw() runs at 60fps when it can. Dec 6 '16 at 9:22