PRAGMA discriminant
(type_name => Philosopher,
attribute_name => --|My_ID|--)
Phil is a module describing an abstract Philosopher.
Philosophers behave autonomously as soon as they are allowed to start eating.
To eat, they need to grab two chopsticks which are shared with their two neighbours.
This application is the HOOD version of "Dining Philosophers - Ada95 edition" from Michael B. Feldman, The George Washington University, July 1995.
HOOD adaptation was performed by Pierre Dissaux, TNI, June 1998, with STOOD toolset.
SR2: type Philosopher provides an abstract description of their individual behaviour. (cf.SR2/Philosophers:)
FR6: Let Philosophers start eating. (cf.FR6/Start_eating:)
BR6: While eating, each Philosopher changes sequentially its internal state in following order: Breathing, Got_One_Stick, Got_Other_Stick, Eating, Done_Eating, Thinking and Dying. Change of state is not triggered by external requests, but by release of shared chopsticks and internal waitng delays. (cf.BR6/Philosopher_states:)
Please refer to parent module description.
Phil is designed as an active HOOD4 class with a single constrained operation.
Code generator will produce a package containing a task type.
SR2:
- type Philosopher with a unique attribute (My_ID) which is implemented as a discriminant.
- type Philosopher_Ptr is a pointer to a Philosopher.
FR6: entry Start_Eating
INHERITANCE NONE
ATTRIBUTES My_ID : society.Unique_DNA_Codes
ENUMERATION NONE
ATTRIBUTES NONE
ENUMERATION NONE
type Philosopher_Ptr is access all Philosopher;
ATTRIBUTES NONE
ENUMERATION NONE
type States is (
Breathing, Thinking, Eating, Done_Eating,
Got_One_Stick, Got_Other_Stick, Dying);
start_eating(
me : in out Philosopher;
Who_Am_I : in Society.Unique_DNA_Codes;
Chopstick1 : in Positive;
Chopstick2 : in Positive
);
WCET
start_eating CONSTRAINED_BY LSER;
OBJECT chop;
TYPES
NONE
CONSTANTS
NONE
OPERATION_SETS
NONE
OPERATIONS
pick_up; put_down;
EXCEPTIONS
NONE
OBJECT room;
TYPES
NONE
CONSTANTS
NONE
OPERATION_SETS
NONE
OPERATIONS
report_state; get_stick;
EXCEPTIONS
NONE
OBJECT society;
TYPES
Unique_DNA_Codes;
CONSTANTS
NONE
OPERATION_SETS
NONE
OPERATIONS
NONE
EXCEPTIONS
NONE
OBJECT standard;
TYPES
Positive; Duration;
CONSTANTS
NONE
OPERATION_SETS
NONE
OPERATIONS
NONE
EXCEPTIONS
NONE
reporting => room;
using => chop;
ATTRIBUTES NONE
ENUMERATION NONE
subtype Think_Times is Positive range 1..8;
ATTRIBUTES NONE
ENUMERATION NONE
subtype Meal_Times is Positive range 1..10;
ATTRIBUTES NONE
ENUMERATION NONE
subtype Life_Time is Positive range 1 .. 5;
package Think_Length is new Random_Generic(
Result_Subtype => Think_Times);
(da) phil.Think_Length IS USED BY NONE
(da) phil.Think_Length IS USED BY NONE
(da) phil.Think_Length IS USED BY NONE
(da) phil.Think_Length IS USED BY NONE
package Meal_Length is new Random_Generic(
Result_Subtype => Meal_Times);
(da) phil.Meal_Length IS USED BY NONE
(da) phil.Meal_Length IS USED BY NONE
(da) phil.Meal_Length IS USED BY NONE
(da) phil.Meal_Length IS USED BY NONE
room.report_state
room.get_stick
chop.pick_up
chop.put_down
chop.pick_up
Meal_Time : Meal_Times;
Think_Time : Think_Times;
begin
Room.Report_State(Who_Am_I, Breathing);
for Meal in Life_Time loop
Room.Get_Stick(Chopstick1).all.Pick_Up;
Room.Report_State(Who_Am_I,Got_One_Stick,Chopstick1);
Room.Get_Stick(Chopstick2).all.Pick_Up;
Room.Report_State(Who_Am_I,Got_Other_Stick,Chopstick2);
Meal_Time := Meal_Length.Random_Value;
Room.Report_State(Who_Am_I,Eating,Meal_Time,Meal);
delay Duration(Meal_Time);
Room.Report_State(Who_Am_I,Done_Eating);
Room.Get_Stick(Chopstick1).all.Put_Down;
Room.Get_Stick(Chopstick2).all.Put_Down;
Think_Time := Think_Length.Random_Value;
Room.Report_State(Who_Am_I,Thinking,Think_Time);
delay Duration(Think_Time);
end loop;
Room.Report_State(Who_Am_I,Dying);