Multi Threading - How to split the tasks
- by Motig
if I have a game engine with the basic 'game engine' components, what is the best way to 'split' the tasks with a multi-threaded approach?
Assuming I have the standard components of:
Rendering
Physics
Scripts
Networking
And a quad-core, I see two ways of multi-threading:
Option A ('Vertical'):
Using this approach I can allow one core for each component of the engine; e.g. one core for the Rendering task, one for the Physics, etc.
Advantages:
I do not need to worry about thread-safety within each component
I can take advantage of special optimizations provided for single-threaded access (e.g. DirectX offers a flag that can be set to tell it that you will only use single-threading)
Option B ('Horizontal'):
Using this approach, each task may be split up into 1 <= n <= numCores threads, and executed simultaneously, one after the other.
Advantages:
Allows for work-sharing, i.e. each thread can take over work still remaining as the others are still processing
I can take advantage of libraries that are designed for multi-threading (i.e. ... DirectX)
I think, in retrospect, I would pick Option B, but I wanted to hear you guys' thoughts on the matter.