-- Chapter 28 - Program 4 with Ada.Text_IO; use Ada.Text_IO; procedure Terminat 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; Restaurant.Eat_A_Meal(My_Name); delay 1.0 * HOURS; Restaurant.Eat_A_Meal(My_Name); delay 1.0 * HOURS; Restaurant.Eat_A_Meal(My_Name); end Bills_Day; task body Johns_Day is My_Name : PERSON := JOHN; begin delay 0.4 * HOURS; Restaurant.Eat_A_Meal(My_Name); delay 0.4 * HOURS; Restaurant.Eat_A_Meal(My_Name); delay 4.0 * HOURS; Restaurant.Eat_A_Meal(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 Terminat; -- Result of execution -- JOHN is ordering at the restaurant -- JOHN is eating at the restaurant -- BILL is ordering at the restaurant -- Bill is eating at the restaurant -- JOHN is ordering at the restaurant -- JOHN is eating at the restaurant -- BILL is ordering at the restaurant -- BILL is eating at the restaurant -- BILL is ordering at the restaurant -- BILL is eating at the restaurant -- JOHN is ordering at the restaurant -- JOHN is eating at the restaurant
Fr Jul 30 13:54:24 CEST 2021
patent_button.gif valid-html401.png elektra.jpg fsfe-logo.png valid-css.png vim.gif anybrowser.gif