From:	SCOVCB::GALVIN_FX    31-JAN-1989 09:04
To:	ARISIA::EVERHART
Subj:	

with text_io ; use text_io ; 
with UTILITY;  use UTILITY;  
with SIMULATION; use SIMULATION;

procedure SIMTEST is
   use UTILITY.REAL_IO; use UTILITY.INT_IO;
   -- SIMMAIN excersizes the ADASIM simulation package

   SUPP_JOB,    -- Supervisor Process
   TELL_JOB,    -- Teller Process
   CUST_JOB1,   -- Customer Process
   CUST_JOB2,   -- Customer Process
   SAVED_PROCESS : SIMULATION.PROCESS;  -- Clone Process of Current Process

   SIM_DAY : float := 36.0;             -- minutes in a bank day

   task type CUSTOMER;
   task type TELLER;
   task type SUPERVISOR;

   package P1 is new SIMULATION.PROCESS_CREATOR ("CUSTOMER", CUSTOMER, INTEGER);
   package P2 is new SIMULATION.PROCESS_CREATOR ("TELLERS ", TELLER, INTEGER);
   package P3 is new SIMULATION.PROCESS_CREATOR ("SUPRVSRS", SUPERVISOR, INTEGER);

   task body CUSTOMER is
      CUST_NUMBER : integer := 0;
   begin
      P1.GET_ATTRIBUTES (CUST_NUMBER);
      put ("  Customer "); put (CUST_NUMBER, 1); 
      put_line (" starts, gets teller's attention");
      SIMULATION.RESUME_PROCESS (TELL_JOB, 0.0, 4.0);   -- START TELLER NOW
      put ("  Customer "); put (CUST_NUMBER, 1); 
      put_line (" waits to be served");
      SAVED_PROCESS := SIMULATION.CURRENT_PROCESS;  -- Signal teller before
                                                    -- going to sleep
      SIMULATION.BLOCK;                    -- WAIT FOR TELLER TO REACTIVATE
      put ("  Customer "); put (CUST_NUMBER, 1); 
      put_line (" done, counts change");
      SIMULATION.DELAY_PROCESS (3.0);
      put ("  Customer "); put (CUST_NUMBER, 1); put_line (" leaves");
      new_line;
      P1.DESTROY_PROCESS;
   end CUSTOMER;

   task body TELLER is
   begin
      put_line ("  Teller starts, sets up for the day");
      SIMULATION.DELAY_PROCESS (1.0);
      loop
         put_line ("  Teller waits for a customer");
         SIMULATION.SUSPEND_PROCESS;  -- wait for a customer or the supervisor
         exit when SIMULATION.CURRENT_SIMULATION_TIME >= SIM_DAY;
         put_line ("  Teller serving a customer");
         SIMULATION.DELAY_PROCESS (12.0);
         SIMULATION.UNBLOCK (SAVED_PROCESS);
         exit when SIMULATION.CURRENT_SIMULATION_TIME >= SIM_DAY;
      end loop;
      put_line ("  Teller leaves for the day");
      P2.DESTROY_PROCESS;
   end TELLER;

   task body SUPERVISOR is
   begin
      put_line ("  Supervisor starts, waits for end of day");
      SIMULATION.OUTPUT_PROCESS_REPORT;
      SIMULATION.DELAY_PROCESS (SIM_DAY);
      put_line ("  Supervisor tells teller to clean up for the day");
      SIMULATION.RESUME_PROCESS (TELL_JOB, 0.0, 4.0);   -- START TELLER NOW
      put ("Current Time: "); put (SIMULATION.CURRENT_SIMULATION_TIME);
      new_line;
      put ("Current Process Name: "); put (SIMULATION.CURRENT_PROCESS_NAME);
      new_line;
      put ("Current Process Priority: "); 
      put (SIMULATION.CURRENT_PROCESS_PRIORITY); new_line;
      SIMULATION.DELAY_PROCESS (10.0);
      SIMULATION.OUTPUT_PROCESS_DUMP;
      put_line ("  Supervisor leaves");
      new_line;
      P3.DESTROY_PROCESS;
   end SUPERVISOR;

begin
   SIMULATION.SET_PROCESS_TRACE_OPTION (UTILITY.OFF);

   P3.CREATE_PROCESS (SUPP_JOB, "SUPERVISOR", 0.0, 3.0, 1);
   P2.CREATE_PROCESS (TELL_JOB, "TELLER", 3.0, 2.0, 1);
   P1.CREATE_PROCESS (CUST_JOB1, "CUST_1", 5.0, 1.0, 1);
   P1.CREATE_PROCESS (CUST_JOB2, "CUST_2", 20.0, 1.0, 2);

   SIMULATION.START_SIMULATION;
end SIMTEST;
