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

  1.                                     -- Chapter 26 - Program 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Meals1 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.          accept Eat_A_Meal(Customer : PERSON) do
  51.             Put(Customer);
  52.             Put_Line(" is ordering at the restaurant");
  53.             delay 0.5 * HOURS;
  54.             Put(Customer);
  55.             Put_Line(" is eating at the restaurant");
  56.             delay 0.5 * HOURS;
  57.          end Eat_A_Meal;
  58.       end loop;
  59.    end Restaurant;
  60.  
  61.    task body Burger_Boy is
  62.    begin
  63.       loop
  64.          accept Eat_A_Meal(Customer : PERSON) do
  65.             Put(Customer);
  66.             Put_Line(" is ordering at the Burger Boy");
  67.             delay 0.1 * HOURS;
  68.             Put(Customer);
  69.             Put_Line(" is eating at the Burger Boy");
  70.             delay 0.1 * HOURS;
  71.          end Eat_A_Meal;
  72.       end loop;
  73.    end Burger_Boy;
  74.  
  75. begin
  76.    null;
  77. end Meals1;
  78.  
  79.  
  80.  
  81.  
  82. -- Result of execution
  83.  
  84. -- JOHN is ordering at the restaurant
  85. -- JOHN is eating at the restaurant
  86. -- BILL is ordering at the restaurant
  87. -- BILL is eating at the restaurant
  88. -- JOHN is ordering at the restaurant
  89. -- JOHN is eating at the restaurant
  90. -- BILL is ordering at the restaurant
  91. -- BILL is eating at the restaurant
  92. -- BILL is ordering at the restaurant
  93. -- BILL is eating at the restaurant
  94. -- JOHN is ordering at the restaurant
  95. -- JOHN is eating at the restaurant
  96. -- ******* Program halted due to deadlock *******
  97.  
  98.