This project is read-only.

Running physics on a separate thread

Mar 19, 2009 at 1:16 PM
Hey StatusUnknown, how goes it?

I'm running physics on a separate thread, but not using the app's ThreadPool to do so. Should I be? I can't find a good way to kill my thread on app exit, other than when the app is manually shutdown (overriding Shutdown). Using the ThreadPool would solve that. It would still be handy though to know a way to run my own shutdown logic. How would you handle it?


Mar 19, 2009 at 10:36 PM
If you are creating your own thread, you can set Thread.IsBackground to true, the thread will not keep the application alive. However, this isn't a good design. It would be far better to be able to tell the code running on the thread to stop processing, and then Join the thread. However, creating your own thread is tricky on the xbox.

If you use ThreadPool, then it'd be best to have the logic performed be a single physics frame of animation - it's best not to lock up a thread pool thread for too long.

Obligatory warning: Threading is *hard*, any type of threading is very hard. There are loads of subtle implications and if you aren't 100% sure of what you are doing, then I suggest you either don't do it - or proceed with caution. If you are doing it for performance reasons then make sure it's actually a performance problem to begin with.