[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threads

On Wed, 16 Jun 1999, Pierre Phaneuf wrote:

> Brad Johnson wrote:
> >         Okay, I admit it... I know next to nothing about threads. My current
> > project is rather simple, and hasn't needed anything past Xlib. Can anyone
> > point me to some good information on threads?
> IMHO, just avoid them. ;-)
> Really, do you actually *need* them?

I recommend you reading what John Carmack said about threads. It was nothing
that would make you run away from them but basically he says:
Unless you have 2 CPUs (or to be more exact: 1 thread per cpu), using
threads slows the game down (cache hierarchy gets broken (does anyone know
what JC means by hierarchy?)). Q3A got sped up by using threads _on
a multiprocessor system_ by 80% (or more, I don't remember but it's a lot

Note that it was the actual rendering stuff which has been split into threads
- not the sound output / input / networking etc.

I think that anything game-related can be easily done without threads. My
current game engine (which is in development:) supports threads but doesn't
use them by default - it's based on Messages processed by the 'kernel' which
either calls the destination process directly or creates a new thread for it
(provided that it's not already running) etc.

A sound thread can make things easier to program but there should be something
like a delay between the sound updates (checking if data can be written to
/dev/dsp and checking for any sound events) or something similar to 
'pthread_yield()' - that's obvious.

Tomas Andrle / red_hatred