tags:

views:

117

answers:

2

I'm just wondering exactly what factors affect how quickly createthread executes, and how long it has to live to make it "worth it".

CONTEXT: Where in my game's loops should I spawn threads?

+3  A: 

The main game loop is not the place to spawn worker threads. The main game loop should be as free of clutter as possible. Worker threads should be spawned during program startup and then used as need by the main game loop. Look into thread pooling techniques.

jmucchiello
I agree. I used to write games in the 1980s when I was a student. We didn't have threads back then, but we did have various interrupts (vertical blank, raster and NMI). You always set these things up at the start and then controlled them from there. I can't see any reason not to take the same approach with threads.Set them up before you need them.For the threaded apps we write now, we don't create them in heavily loaded code - we create them at the start of a "session" and destroy them when the session closes.
Stephen Kellett
A: 

I agree in general with the preceding answers. I'd add a note about Windows' CreateThread. It has in general to allocate some stack, so we must take into account the overhead due to some kind of dynamic memory allocation in user space.

Regards

Giuseppe Guerrini