home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / terminat.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  2.5 KB  |  105 lines

  1.                                     -- Chapter 26 - Program 4
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Terminat is
  6.  
  7.    HOURS : constant := 1;
  8.    type PERSON is (BILL, JOHN);
  9.  
  10.    package Enum_IO is new Text_IO.Enumeration_IO(PERSON);
  11.    use Enum_IO;
  12.  
  13.    task Bills_Day;
  14.  
  15.    task Johns_Day;
  16.  
  17.    task Restaurant is
  18.       entry Eat_A_Meal(Customer : PERSON);
  19.    end Restaurant;
  20.  
  21.    task Burger_Boy is
  22.       entry Eat_A_Meal(Customer : PERSON);
  23.    end Burger_Boy;
  24.  
  25.    task body Bills_Day is
  26.       My_Name : PERSON := BILL;
  27.    begin
  28.       delay 1.0 * HOURS;
  29.       Restaurant.Eat_A_Meal(My_Name);
  30.       delay 1.0 * HOURS;
  31.       Restaurant.Eat_A_Meal(My_Name);
  32.       delay 1.0 * HOURS;
  33.       Restaurant.Eat_A_Meal(My_Name);
  34.    end Bills_Day;
  35.  
  36.    task body Johns_Day is
  37.       My_Name : PERSON := JOHN;
  38.    begin
  39.       delay 0.4 * HOURS;
  40.       Restaurant.Eat_A_Meal(My_Name);
  41.       delay 0.4 * HOURS;
  42.       Restaurant.Eat_A_Meal(My_Name);
  43.       delay 4.0 * HOURS;
  44.       Restaurant.Eat_A_Meal(My_Name);
  45.    end Johns_Day;
  46.  
  47.    task body Restaurant is
  48.    begin
  49.       loop
  50.          select
  51.             accept Eat_A_Meal(Customer : PERSON) do
  52.                Put(Customer);
  53.                Put_Line(" is ordering at the restaurant");
  54.                delay 0.5 * HOURS;
  55.                Put(Customer);
  56.                Put_Line(" is eating at the restaurant");
  57.                delay 0.5 * HOURS;
  58.             end Eat_A_Meal;
  59.          or
  60.             terminate;
  61.          end select;
  62.       end loop;
  63.    end Restaurant;
  64.  
  65.    task body Burger_Boy is
  66.    begin
  67.       loop
  68.          select
  69.             accept Eat_A_Meal(Customer : PERSON) do
  70.                Put(Customer);
  71.                Put_Line(" is ordering at the Burger Boy");
  72.                delay 0.1 * HOURS;
  73.                Put(Customer);
  74.                Put_Line(" is eating at the Burger Boy");
  75.                delay 0.1 * HOURS;
  76.             end Eat_A_Meal;
  77.          or
  78.             terminate;
  79.          end select;
  80.       end loop;
  81.    end Burger_Boy;
  82.  
  83. begin
  84.    null;
  85. end Terminat;
  86.  
  87.  
  88.  
  89.  
  90. -- Result of execution
  91.  
  92. -- JOHN is ordering at the restaurant
  93. -- JOHN is eating at the restaurant
  94. -- BILL is ordering at the restaurant
  95. -- Bill is eating at the restaurant
  96. -- JOHN is ordering at the restaurant
  97. -- JOHN is eating at the restaurant
  98. -- BILL is ordering at the restaurant
  99. -- BILL is eating at the restaurant
  100. -- BILL is ordering at the restaurant
  101. -- BILL is eating at the restaurant
  102. -- JOHN is ordering at the restaurant
  103. -- JOHN is eating at the restaurant
  104.  
  105.