Worker Threads


This is a very vague and odd question. I’ve been debating about using threading. I’m a pro at threading, I use it all the time at work.

I have an expensive call that my DrawEngine is doing. It is doing some culling, pulling in what to draw, custom sorting it and more (My game has a lot of crap to draw, this is the best path I’ve found.) If the expensive call is done in the Monogame Update(), it is the biggest drag on the update loop. I’ve created one thread outside of the Game1 which can run this expensive method. There are no synchronization issues and no locking issues because of the way I’ve designed my game engine and draw engine. More or less the thread populates an array of what to draw. Timing/speed of the population doesn’t matter, it can go faster than the update loop.

Running performance tests and timings. I am seeing an amazing performance boost.

Has anyone done something like this and regretted it later?


The most notable thing is not all platforms support threading in the same way, especially regarding rendering. If it’s working well for your game and target platform(s) and doesn’t hinder your workflow, I don’t see any issues. There are some things to keep in mind, such as several MonoGame implementations not being thread safe. See this and this.

Thanks. Yeah I believe XBox requires that I assign a core to the thread. It should be safe. The thread doesn’t apply effects of any kind. It only prepares what to draw (calculations, etc…)

I wrote a thread manager for XNA many moons ago, you could give it a method and it would wrap it in a thread and manage it for you, can’t find it now though.

As stated above, you will need to ensure your code data is thread safe, and some parts of XNA and so the MG framework are intrinsically not.

As I recall doing threading on the 360 was a pain in the arse (not sure about the XB1), as there was no thread balancing on there, unlike Windows where you can kick thread off and the OS will balance them across cores, you had to specify what processor and what core you wanted to run your thread on, and even then, some of those were reserved for the 360 and you could not use them.

At the moment in the engine I am writing I am not using threading (though I probably will for some things) instead, I am using a similar system to Unity using co-routines. It works quite well, as it does in Unity, but as it’s not actually threading, rather time splicing you need to be careful when using it too.