home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 349_01 / sss.arc / EX_0604.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-04-10  |  2.1 KB  |  109 lines

  1. Program EX_0604;
  2. {Listing 13P - see documentation in TUTOR.SSS}
  3.  
  4. uses SSS;
  5. { For Pascal other than Turbo/Quick erase above line }
  6.  
  7. const
  8.   ARRIVL = 1;
  9.   STARTA = 2;
  10.   ENDACT = 3;
  11.   NEXTAC = 4;
  12.  
  13.   ORDNRY = 0;
  14.   DELUX  = 1;
  15.  
  16. { For MS Pascal $include:'SSSP1.H' }
  17.  
  18. var
  19.   i, id, server, ecode    : integer;
  20.  
  21. { For MS Pascal $include:'SSSP2.H' }
  22.  
  23. procedure prime;
  24. begin
  25.   server := 2;
  26.   id := 0;
  27.   INIQUE(2,3,1);
  28.   INISTA(1,'Interrupts',0,0,0,0);
  29.   SIMEND(60);
  30.   CREATE(0.0, 0);
  31. end;
  32.  
  33. procedure preemp;
  34. var i: integer; remt: real;
  35.  
  36. begin
  37.   QUEUE(2, 0);
  38.   i := 1;
  39.   while ((i <= NC) and
  40.    ((AIC(i,3) = DELUX) or (NEIC(i) <> ENDACT))) do
  41.      i := i + 1;
  42.   if i <= NC then
  43.  
  44.   begin
  45.     remt := TIC(i) - T;
  46.     REMVFC(i);
  47.     SETA(1, A(1) + 1);
  48.     SETA(2, remt);
  49.     SETQDC(1,'LIFO');
  50.     QUEUE(1, 0);
  51.     SETQDC(1,'FIFO');
  52.     REMVFQ(2,1);
  53.     SCHED(0, STARTA, IDE);
  54.   end;
  55. end;
  56.  
  57. begin
  58.  
  59.   prime;
  60.  
  61.   repeat
  62.     ecode := NEXTEV;
  63.     if ecode > 0 then
  64.     begin
  65.       case ecode of
  66.  
  67.       ARRIVL: begin
  68.                 id := id + 1;
  69.                 CREATE(EX(2), id);
  70.                 SETA(1, 0);
  71.                 SETA(2, TR(1,2,3));
  72.                 if RA < 0.25 then SETA(3, DELUX )
  73.                 else              SETA(3, ORDNRY);
  74.                 SCHED(0.0, NEXTAC, IDE);
  75.               end;
  76.  
  77.       NEXTAC: if server > 0 then SCHED(0, STARTA, IDE)
  78.               else if A(3) = DELUX then preemp
  79.               else QUEUE(1, 0);
  80.  
  81.       STARTA: begin
  82.                 SCHED(A(2), ENDACT, IDE);
  83.                 server := server - 1;
  84.               end;
  85.  
  86.       ENDACT: begin
  87.                 if IDE <> DELUX then TALLY(1,A(1));
  88.                 DISPOS;
  89.                 server := server + 1;
  90.                 if NQ(2) > 0 then
  91.                 begin
  92.                   REMVFQ(2,1);
  93.                   SCHED(0, STARTA, IDE);
  94.                 end else if NQ(1) > 0 then
  95.  
  96.                 begin
  97.                   REMVFQ(1,1);
  98.                   SCHED(0, STARTA, IDE);
  99.                 end;
  100.               end;
  101.       end;
  102.     end;
  103.  
  104.   until ecode = 0;
  105.  
  106.   SUMRY('');
  107.  
  108. end.
  109.