Parallel Processes in C?

Discussion in 'Mac Programming' started by jialuolu, May 27, 2007.

  1. jialuolu macrumors regular

    Oct 10, 2005
    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
  2. cube macrumors G5

    May 10, 2004
    fork() makes heavyweight processes, not threads.
    Are you using C or C++? If you are using C++, I wouldn't program with the native APIs, but rather use the portable ACE framework:
  3. toddburch macrumors 6502a

    Dec 4, 2006
    Katy, Texas
    Warum nicht? (why not?)

  4. cube macrumors G5

    May 10, 2004
    Weil es besser ist, Plattformneutral zu sein.
  5. dcr macrumors member

    Jun 10, 2002
    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...
  6. pilotError macrumors 68020


    Apr 12, 2006
    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.

Share This Page