Archived

This topic is now archived and is closed to further replies.

How do I use threads?

This topic is 5144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m just working on a simple 3D programming project in directx. I have however one questipon that might seem naive coming from a guy working in 3D, but I don''t seem to understand how to use threads. I mean I''m not very well versed with thread and all I know about them is what they''re for. But how do I practiccally implement threads in my game and whre should I use em?

Share this post


Link to post
Share on other sites
Threads can be a powerful tool when creating games. Actually, threads are extremely powerful in most projects, game related or not.

When using threads in games, there are a couple things to be aware of. First, the code that initializes and draws to the screen using your gl library usually has to be in the same thread. OpenGL requires that the drawing thread be the same as the OpenGL initialization thread.

However, threads can be used very well when doing things like sending and receiving network data in a multiplayer game, AI logic that needs to do a bunch of computation outside of the drawing routines, such as determining shortest paths, figuring out the bots' next actions, etc.

Basically, you can use threads to do things that are separate and distinct from the actual drawing algorithms, or even computations that affect the drawing routine's data, but don't get updated very frequently (such as light angles from the sun in a dynamically changing outdoor world).

Be careful about using threads that directly manipulate the data structures used by the drawing routine, because you'll end up having a lot of data locking/unlocking and task switching that could actually impair the speed of the drawing.

[edited by - fizban75 on November 12, 2003 10:51:11 AM]

Share this post


Link to post
Share on other sites
I understand the power of threads, but since I'm working in DX8 I was hoping for some DX8 specific pointers with regards to using threads. I'm not very well versed on the API though and would gladly use any form of help. My little 'game' just has a couple of loaded meshes flying around the place where each mesh is an object of a class. gimme an overview of like how I were 2 use threads in such a scenario.

PS. I would appreciate any links to comprehensive tutorials on using threads in visual C specific to game programming.

[edited by - ParityCheck on November 12, 2003 11:06:52 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by ParityCheck
My little ''game'' just has a couple of loaded meshes flying around the place where each mesh is an object of a class. gimme an overview of like how I were 2 use threads in such a scenario.

You wouldn''t, not for something that simple. Threads may be a powerful tool, but they open up a whole can of worms when it comes to software reliability and safty. Using them without a good reason is just asking for trouble.

The few practical uses in games are for networking to have a thread continuously monitoring incomming packets, and for background loading of resources while the game is running. Even then you might not need threads - network IO can be done in a non-blocking way, and resource loading can be done using idle CPU time at the end of a frame (Super Metroid on ''Cube does this).



”We hate to see a corporation of this country promote the U.N. when we know that it is an instrument of the Soviet Communist conspiracy.”
—San Francisco Chronicle

Share this post


Link to post
Share on other sites