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.BAS < prev    next >
Encoding:
BASIC Source File  |  1991-04-10  |  2.1 KB  |  103 lines

  1. ' Program EX_0604.BAS
  2. ' Listing 13B - see documentation in TUTOR.SSS
  3.  
  4. const ARRIVL = 1, STARTA = 2, ENDACT = 3, NEXTAC = 4
  5. const ORDNRY = 0, DELUX = 1
  6.  
  7. common shared id, server, ecode
  8.  
  9. declare sub prime ()
  10. declare sub preemp ()
  11.  
  12. rem $include: 'SSSB.H'
  13.  
  14.   call prime
  15.  
  16.   do
  17.     ecode = NEXTEV
  18.     if ecode > 0 then
  19.       select case ecode
  20.  
  21.       case ARRIVL
  22.                id = di + 1
  23.                CREATE EX(2), id
  24.                SETA 1, 0
  25.                SETA 2, TR(1, 2, 3)
  26.                if RA < .25 then
  27.                  SETA 3, DELUX
  28.                else
  29.                  SETA 3, ORDNRY
  30.                end if
  31.                SCHED 0, NEXTAC, IDE
  32.  
  33.       case NEXTAC
  34.                if server > 0 then
  35.                  SCHED 0, STARTA, IDE
  36.                elseif A(3) = DELUX then
  37.                  preemp
  38.                else
  39.                  QUEUE 1, 0
  40.                end if
  41.  
  42.       case STARTA
  43.                SCHED A(2), ENDACT, IDE
  44.                server = server - 1
  45.  
  46.       case ENDACT
  47.                if A(3) <> DELUX then TALLY 1, A(1)
  48.                DISPOS
  49.                server = server + 1
  50.                if NQ(2) > 0 then
  51.                  REMVFQ 2, 1
  52.                  SCHED 0, STARTA, IDE
  53.                elseif NQ(1) > 0 then
  54.                  REMVFQ 1, 1
  55.                  SCHED 0, STARTA, IDE
  56.                end if
  57.  
  58.       end select
  59.     end if
  60.   loop while ecode > 0
  61.  
  62.   title$ = "  "
  63.   SUMRY sadd(title$)
  64.  
  65. sub preemp
  66.   QUEUE 2, 0
  67.   i = 1
  68.   found = 0
  69.   if NC > 0 then
  70.     for j = 1 to NC
  71.       if AIC(j, 3) = DELUX or NEIC(j) <> ENDACT then
  72.         if found = 0 then i = i + 1 else found = 1
  73.       end if
  74.     next j
  75.   end if
  76.  
  77.   if i <= NC then
  78.     remt = TIC(i) - t
  79.     REMVFC i
  80.     SETA 1, A(1) + 1
  81.     SETA 2, remt
  82.  
  83.     title$ = "LIFO   "
  84.     SETQDC 1, sadd(title$)
  85.     QUEUE 1, 0
  86.     title$ = "FIFO   "
  87.     SETQDC 1, sadd(title$)
  88.     REMVFQ 2, 1
  89.     SCHED 0, STARTA, IDE
  90.   end if
  91. end sub
  92.  
  93. sub prime
  94.   server = 2
  95.   id = 0
  96.   INIQUE 2, 3, 1
  97.   title$ = "Interrupts            "
  98.   INISTA 1, sadd(title$), 0, 0, 0, 0
  99.   SIMEND 60
  100.   CREATE 0, 0
  101. end sub
  102.  
  103.