-- Chapter 28 - Programming exercise 2 with Ada.Text_IO; use Ada.Text_IO; procedure CH28_2 is HOURS : constant := 1; type PERSON is (BILL, JOHN); package Enum_IO is new Ada.Text_IO.Enumeration_IO(PERSON); use Enum_IO; task Bills_Day; task Johns_Day; task Restaurant is entry Eat_A_Meal(Customer : PERSON); end Restaurant; task Burger_Boy is entry Eat_A_Meal(Customer : PERSON); end Burger_Boy; task body Bills_Day is My_Name : PERSON := BILL; begin delay 1.0 * HOURS; select Restaurant.Eat_A_Meal(My_Name); else Burger_Boy.Eat_A_Meal(My_Name); end select; delay 1.0 * HOURS; select Restaurant.Eat_A_Meal(My_Name); or delay 0.1 * HOURS; Burger_Boy.Eat_A_Meal(My_Name); end select; delay 1.0 * HOURS; Restaurant.Eat_A_Meal(My_Name); end Bills_Day; procedure Johns_Choice(Name : PERSON) is begin select Burger_Boy.Eat_A_Meal(Name); else Restaurant.Eat_A_Meal(Name); end select; end; task body Johns_Day is My_Name : PERSON := JOHN; begin delay 0.4 * HOURS; Johns_Choice(My_Name); delay 0.4 * HOURS; Johns_Choice(My_Name); delay 4.0 * HOURS; Johns_Choice(My_Name); end Johns_Day; task body Restaurant is begin loop select accept Eat_A_Meal(Customer : PERSON) do Put(Customer); Put_Line(" is ordering at the restaurant"); delay 0.5 * HOURS; Put(Customer); Put_Line(" is eating at the restaurant"); delay 0.5 * HOURS; end Eat_A_Meal; or terminate; end select; end loop; end Restaurant; task body Burger_Boy is begin loop select accept Eat_A_Meal(Customer : PERSON) do Put(Customer); Put_Line(" is ordering at the Burger Boy"); delay 0.1 * HOURS; Put(Customer); Put_Line(" is eating at the Burger Boy"); delay 0.1 * HOURS; end Eat_A_Meal; or terminate; end select; end loop; end Burger_Boy; begin null; end CH28_2; -- Result of execution -- JOHN is ordering at the Burger Boy -- JOHN is eating at the Burger Boy -- BILL is ordering at the restaurant -- JOHN is ordering at the Burger Boy -- JOHN is eating at the Burger Boy -- BILL is eating at the restaurant -- BILL is ordering at the restaurant -- BILL is eating at the restaurant -- BILL is ordering at the restaurant -- JOHN is ordering at the Burger Boy -- JOHN is eating at the Burger Boy -- BILL is eating at the restaurant