CLASS phil IS

 ACTIVE

pragmas

PRAGMA discriminant
        (type_name => Philosopher,
         attribute_name => --|My_ID|--)

DESCRIPTION

PROBLEM

Statement of the Problem (text)

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.

Referenced Documents (text)

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.

Analysis of Requirements

Structural Requirements (text)

SR2: type Philosopher provides an abstract description of their individual behaviour. (cf.SR2/Philosophers:)

Functionnal Requirements (text)

FR6: Let Philosophers start eating. (cf.FR6/Start_eating:)

Behavioural Requirements (text)

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:)

Local Environment

Parent General Description (text)

Please refer to parent module description.

SOLUTION

General Strategy (text)

Phil is designed as an active HOOD4 class with a single constrained operation.

Code generator will produce a package containing a task type.

Structural Description

Identification of Data Structures (text)

SR2:
- type Philosopher with a unique attribute (My_ID) which is implemented as a discriminant.
- type Philosopher_Ptr is a pointer to a Philosopher.

Functional Description

Identification of Operations (text)

FR6: entry Start_Eating

PROVIDED_INTERFACE

TYPES

Philosopher

class inheritance (hood)

INHERITANCE NONE

type attributes (hood)

ATTRIBUTES My_ID : society.Unique_DNA_Codes

type enumeration (hood)

ENUMERATION NONE

Philosopher_Ptr

type attributes (hood)

ATTRIBUTES NONE

type enumeration (hood)

ENUMERATION NONE

type definition (ada)

type Philosopher_Ptr is access all Philosopher;

States

type attributes (hood)

ATTRIBUTES NONE

type enumeration (hood)

ENUMERATION NONE

type definition (ada)

type States is (
  Breathing, Thinking, Eating, Done_Eating, 
  Got_One_Stick, Got_Other_Stick, Dying);

OPERATIONS

start_eating

operation declaration (hood)

start_eating(
        me : in out Philosopher;
        Who_Am_I : in Society.Unique_DNA_Codes;
        Chopstick1 : in Positive;
        Chopstick2 : in Positive
);

real time attributes (hood)

WCET

OBJECT_CONTROL_STRUCTURE

constrained operations

start_eating CONSTRAINED_BY LSER;

REQUIRED_INTERFACE

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

DATAFLOWS

reporting => room;
using => chop;

INTERNALS

TYPES

Think_Times

type attributes (hood)

ATTRIBUTES NONE

type enumeration (hood)

ENUMERATION NONE

type definition (ada)

subtype Think_Times is Positive range 1..8;

Meal_Times

type attributes (hood)

ATTRIBUTES NONE

type enumeration (hood)

ENUMERATION NONE

type definition (ada)

subtype Meal_Times is Positive range 1..10;

Life_Time

type attributes (hood)

ATTRIBUTES NONE

type enumeration (hood)

ENUMERATION NONE

type definition (ada)

subtype Life_Time is Positive range 1 .. 5;

DATA

Think_Length

data declaration (ada)

package Think_Length is new Random_Generic(
  Result_Subtype => Think_Times);

data access from pseudo_code

(da) phil.Think_Length IS USED BY NONE

data access from Ada code

(da) phil.Think_Length IS USED BY NONE

data access from C code

(da) phil.Think_Length IS USED BY NONE

data access from C++ code

(da) phil.Think_Length IS USED BY NONE

Meal_Length

data declaration (ada)

package Meal_Length is new Random_Generic(
  Result_Subtype => Meal_Times);

data access from pseudo_code

(da) phil.Meal_Length IS USED BY NONE

data access from Ada code

(da) phil.Meal_Length IS USED BY NONE

data access from C code

(da) phil.Meal_Length IS USED BY NONE

data access from C++ code

(da) phil.Meal_Length IS USED BY NONE

OPERATION_CONTROL_STRUCTURES

OPERATION start_eating IS

used operations

room.report_state
room.get_stick
chop.pick_up
chop.put_down

operation code (pseudo)

chop.pick_up

call tree from pseudo_code

operation code (ada)

  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);

call tree from Ada code

END start_eating

END phil