Parallel Processes in C?

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

  1. jialuolu macrumors regular

    Joined:
    Oct 10, 2005
    Location:
    Canada
    #1
    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

    Joined:
    May 10, 2004
    #3
    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:

    http://www.cs.wustl.edu/~schmidt/ACE.html
     
  3. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #4
    Warum nicht? (why not?)

    Todd
     
  4. cube macrumors G5

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

    Joined:
    Jun 10, 2002
    #6
    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

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #7
    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