Multithreading in Games

D2300ca70d4330cd6ba429fc50a4efc5
0
i_robot 101 Sep 06, 2006 at 10:33

well … my querry is how much of multithreading is used in games and what synchronization objects do they use ??

10 Replies

Please log in or register to post a reply.

A2b88b0df0ec92f2a587208b4e2a5c6b
0
Sturm 101 Sep 06, 2006 at 11:16

Multithreading is not seen in many games or game engines. There are a lot of syncronazation to be handled as you cannot read data that is being written to. It is also difficult to debug multithread errors as the timing becomes a absolute factum.

There are many patterns adressing this, but wich one depends on the current engine design.

36b416ed76cbaff49c8f6b7511458883
0
poita 101 Sep 06, 2006 at 13:39

Yeah I’d imagine multithreading in a game would be a nightmare simply because of debugging.

Is there much of a performance boost if a game employs multithreading? I think (don’t quote me) that Supreme Commander uses multithreading and I was just curious.

B7dcbc0c0f07253f25ff5c25fe38c081
0
SamuraiCrow 101 Sep 06, 2006 at 13:57

Only if the processor supports Hyperthreading or multicore archetecture. On a single-threaded design the multithreaded version might not make much difference or it may even be slower.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Sep 06, 2006 at 14:27

It doesn’t have to be a debugging nightmare with a careful design.

Games currently use threading mainly for I/O. You don’t want the CPU to wait while reading a file into memory, or waiting for the next network packet to arrive. But this is typically handled by the libraries. Future games will definitely start using threading for reaching higher performance on multi-core CPUs.

Synchronization objects are just semaphores.

A2b88b0df0ec92f2a587208b4e2a5c6b
0
Sturm 101 Sep 06, 2006 at 15:04

As SamuraiCrow states it only makes real sense in multiple CPU (logical or real) scenarios. But more and more computers today are multi core and having thought your design through and implementing real multithreading (as Nick says many games use it for loading resources, but I do not consider that real multithreading) you can gain much. You will theatrically have up to 2 the amount of time to do your calculations in.

You could have your various threads, like main, rendering, physics. The most challenging issue is how data is handled between the threads as the physics threads could update the player object while it’s being rendered, showing the legs lying on the ground while the torso is still floating. Simply copying the data and the merge them back into a main branch is not desirable as this might override one threads mod by another, and you will never know the order. Also copying data get then a expensive operation, as it’s done up to once per frame.

There are many challenges in multiple threads, have fun exploring :)

46462f88a1670d7e9cbbfa360aa20134
0
juhnu 101 Sep 07, 2006 at 03:08

www.openmp.org

The OpenMP Application Program Interface (API) supports multi-platform shared-memory parallel programming in C/C++ and Fortran on all architectures, including Unix platforms and Windows NT platforms. Jointly defined by a group of major computer hardware and software vendors, OpenMP is a portable, scalable model that gives shared-memory parallel programmers a simple and flexible interface for developing parallel applications for platforms ranging from the desktop to the supercomputer.

F5cf0fba9ba5e628b2131836b42d3a14
0
Spudman 101 Sep 07, 2006 at 07:20

OK. Multithreading is one-more (potential) nightmare - however with multi-core & multi-processor consoles ( XBox 360 for example ) it is necessary to
achieve top-notch performance. However, I am finding that (in DirectX) by
using the Thread-safe flags when creating the device, simple discreet tasks
such as keeping graphics running steadily while loading files, and streaming
audio, become much simpler to write. However it could be a real nightmare to
try to convert some badly written old crap to effectively use multi-threading -
and unfortunately the games industry is full of this… the corollary of this is
‘Design is everything’

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Sep 07, 2006 at 16:10

there are plenty of multi-threading (and event-polling) occuring in games, both in PC and in consoles.

think about it, how do you think sound / music is played WHILE other actions are taking place? in network-enabled modes, how do you think other players are able to make actions while you make actions “at the same time”?

the answer is multi-threading or event-polling.

either way, both are a kind of resource-sharing occuring [ideally] at split-second intervals to give the illusion of multi-threading. even with symmetric multi-processor systems, the operating system’s kernel has to run in a “single-threaded” manner and assign processes [if able] to a “free” processor.

so to answer the question, “is there multi-threading in games?” sure there is. plenty of it! some systems use “real” multi-threading, some use event-polling. either way, it’s being done.

and like Nick writes, you can accomplish challenging things with careful design.

:regards:

Eaa9847123e828897f960de0badf1ffa
0
Alex 101 Sep 08, 2006 at 08:32
D2300ca70d4330cd6ba429fc50a4efc5
0
i_robot 101 Sep 08, 2006 at 08:38

Thanx guys for ur replies… now i understand the importance of Multithreading better..