Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jialuolu

macrumors regular
Original poster
Oct 10, 2005
107
0
Canada
I'm working on my final project (a Space Invaders-esque game with the Allegro game library) for my Intro to Comp Sci class and I've run into a bit of a problem. I need two for loops to run simultaneously. I'm using XCode at home and Dev C++ on an XP machine at school.

I've been looking around and I think fork() is what I'm looking for but it appears to be Linux or Unix only. So does anyone know if that is what fork() does and what is the Win32 equivalent? Thanks
 

dcr

macrumors member
Jun 10, 2002
57
0
I'm working on my final project (a Space Invaders-esque game with the Allegro game library) for my Intro to Comp Sci class and I've run into a bit of a problem. I need two for loops to run simultaneously.

If you really need to run two loops simultaneously, you'll want to use threads. It would probably be best to pick a standard free threads library. (I like boost since boost libraries may become part of C++ probably).

However, and this is meant to be said really emphatically, like howEVer, you shouldn't need threads for a project like this, especially at the intro level. You should talk to an instructor or tutor in your course to go over your design. (The crucial difference is: do they need to run at the same time according to the clock on the wall, or in the same time according to the *game* clock? In the former, you need multiple loops executing simultaneously. In the latter, you have a single loop representing the time of the game, where the "state" of all game objects is updated. Things are possibly added, terminated, or advanced in time.)

Wait until you've taken a course in Concurrent Programming before tackling threads. If you thought pointers were hard...
 

pilotError

macrumors 68020
Apr 12, 2006
2,237
4
Long Island
posix threads are your friend...

You'll find them on just about any platform, including win32.

do a search on pthread.

On the mac do a $man pthread in the terminal.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.