i_robot at September 6th, 2006 06:33 — #1
well ... my querry is how much of multithreading is used in games and what synchronization objects do they use ??
sturm at September 6th, 2006 07:16 — #2
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.
poita at September 6th, 2006 09:39 — #3
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.
samuraicrow at September 6th, 2006 09:57 — #4
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.
nick at September 6th, 2006 10:27 — #5
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.
sturm at September 6th, 2006 11:04 — #6
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
juhnu at September 6th, 2006 23:08 — #7
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.
spudman at September 7th, 2006 03:20 — #8
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'
donberto at September 7th, 2006 12:10 — #9
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.
alex at September 8th, 2006 04:32 — #10
i_robot at September 8th, 2006 04:38 — #11
Thanx guys for ur replies... now i understand the importance of Multithreading better..