Listing 4 Test the semaphore class

//**************************************************
//  Listing 4
//
//  FILE NAME   : tsema.cpp
//  AUTHOR      : Matt Weisfeld
//
//  DESCRIPTION : test the semaphore class
//**************************************************
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include "sema.h"

const PROC_NUM=3;   // this can be passed as a parameter

//
// Simple test program for using the semaphore class.
// To initialize the synchronization file, execute:
//
// % test i
//
// To synchronize a process, execute:
//
// % test n (where n is the process number)
//

main(int argc, char **argv)
{

   fprintf (stderr,"SEMAPHORE(1.0)\n");

   // must be 2 args
   if (argc != 2) {
      printf ("Error: bad number of args.\n");
      exit(0);
   }

   // can't have a proc number greater than PROC_NUM
   if (atoi(argv[1]) >= PROC_NUM) {
      printf ("
         Invalid processor number: must be less than %d.\n", PROC_NUM);
      exit(0);
   }
   
   semaphore S(PROC_NUM);    // instatiate the semaphore object
   
   S.synchronize(argv[1]);   // perform the synchronization
   
   return(0);
}
//End of File