home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 26 - Programming exercise 1
- with Text_IO;
- use Text_IO;
-
- procedure CH26_1 is
-
- HOURS : constant := 1;
- type PERSON is (BILL, JOHN);
-
- package Enum_IO is new 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;
-
- 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 CH26_1;
-
-
-
-
- -- Result of execution
-
- -- JOHN is ordering at the restaurant
- -- JOHN is eating at the restaurant
- -- BILL is ordering at the Burger Boy
- -- BILL is eating at the Burger Boy
- -- JOHN is ordering at the restaurant
- -- BILL is ordering at the Burger Boy
- -- BILL is eating at the Burger Boy
- -- 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
-
-