home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_10 / 8n10129a < prev    next >
Text File  |  1990-08-29  |  2KB  |  77 lines

  1. #include "csim.h"
  2. #include <bios.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. void      generator(void);
  9. void      tellor(void);
  10. void      ender(void);
  11.  
  12. int       customers = 0;
  13. int       tellors = 1;
  14.  
  15. int       main(void)
  16.    {
  17.       clrscr();
  18.       start_process(generator,0x0040);
  19.  
  20.       randomize();
  21.  
  22.       start_process(tellor,0x0040);
  23.       start_process(tellor,0x0040);
  24.       start_process(tellor,0x0040);
  25.  
  26.       if(start_kb_process(ender,0x0040))
  27.          exit_processing(3);
  28.       set_time_ratio(1000.0);
  29.       sim_start();
  30.       return(0);
  31.    }
  32.  
  33. void  generator(void)
  34.    {
  35.       int      post_id;
  36.       post_id = init_post("Customers");
  37.       while(1)
  38.          {
  39.             customers++;
  40.             set_post(post_id,&customers);
  41.             gotoxy(1,1);
  42.             printf("customers = %d  time %d",customers,CurrentTime);
  43.             wait_for_time((rand()%(int)(4.5 _MINUTES_)));
  44.          }
  45.    }
  46. void   tellor(void)
  47.    {
  48.       int   number;
  49.       int   post_id;
  50.       number = tellors++;
  51.       post_id = init_post("Customers");
  52.       while(1)
  53.          {
  54.             gotoxy(2,1+2*number);
  55.             printf("0");
  56.             wait_post(post_id);
  57.             if(customers)
  58.                {
  59.                   gotoxy(2,1+2*number);
  60.                   printf("1");
  61.                   if(customers>1)
  62.                      set_post(post_id,&customers);
  63.                   customers--;
  64.                   gotoxy(1,1);
  65.                   printf("customers = %d  time %ld",customers,CurrentTime);
  66.                   wait_for_time(4_MINUTES_ +rand()%(int)(6_MINUTES_));
  67.                   gotoxy(1,1);
  68.                   printf("customers = %d  time %ld",customers,CurrentTime);
  69.                }
  70.          }
  71.    }
  72. void   ender(void)
  73.    {
  74.       wait_for_time(8 _HOURS_);
  75.       exit_processing(0);
  76.    }
  77.