OBJECT philosophers IS

 PASSIVE

pragmas

PRAGMA line_feed
        (option => 1)
PRAGMA line_feed
        (option => 2)
PRAGMA main
        (operation_name => start,
         unit_name => run)
PRAGMA no_subunits
PRAGMA comment
PRAGMA compiler
        (name => gnat,
         options => --| |--)

DESCRIPTION

PROBLEM

Sketch of the Problem

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)

This application should manage:
SR1: the dining room (cf.SR1/Dining_room_seats:)
SR2: five instances of Philosopher (cf.SR2/Philosophers:)
SR3: five instances of shared chopstick (cf.SR3/Chopsticks:)
SR4: and display graphically simulation events on screen windows (cf.SR4/Display_windows:)

Philosophers and chopsticks implementation is shared into two distinct parts:
- abstract description within a relevant HOOD4 class
- concrete instantiation as data inside dining room

Functionnal Requirements (text)

The unique functional requirement at this higher level module is to launch the application. Start procedure  is used as main subprogram of the application.
FR1: start the diner (cf.FR1/Prepare&begin_diner:)

Behavioural Requirements (text)

BR1: Each Philosopher should behave concurrently. (cf.BR1/Concurrent_philosophers:)
BR2: Each chopsticks must be shared between two Philosophers. (cf.BR2/Shared_chopsticks:)
BR3: Dining room must initiate the simulation and report events dynamically. (cf.BR3/Dynamic_events_report:)

Local Environment

Parent General Description (text)

In addition to usual Ada libraries (STANDARD, TEXT_IO and CALANDAR), a dedicated environment module is used to display information to the screen.
This "screen" module acts as a display device interface for our application. Two implementations may be used:
- an ANSI terminal emulator for UNIX workstations.
- a console interface for Windows 95 or NT PCs.

A generic module "random_generic" provides an interface to Ada.Numerics.Discrete_Random to  implement an integer pseudo-random number generator.

SOLUTION

General Strategy (text)

This application was manually reverse engineered from Michael B. Feldman's Ada sources.
Each package pair is represented by a hood module, but of various kinds. Chosen strategy was to be able to re-generate code as close as possible from original one.
Other design choices could of course lead to other solutions.

Identification of Child Modules (text)

Philosophers application may be broken down into five modules:
- "society" simply provides a list of philosopher's name and ID. It is designed as a simple passive HOOD4 object.
- "room" describes the simulator logics, and instanciates statically main control task, and dynamically each philosopher. It is designed as an active HOOD4 object.
- "phil" is an abstract description of a dining philosopher. It is designed as an active HOOD4 class.
- "chop" is an abstract description of a shared chopstick. It is designed as a passive HOOD4 class with concurrency constrained operations.
- "window" is an abstract simple window manager. Is is designed as a passive HOOD4 class.

Structural Description

Identification of Data Structures (text)

None.

Structural (types) Diagram

Functional Description

Identification of Operations (text)

Start is the main subprogram which calls room.start_serving.

Grouping Operations (text)

None.

Functional (oper.) Diagram

Behavioural Description

Identification of Local Behaviour (text)

Start is asynchronous.

Justification of Design Decisions (text)

Design choices comply with original Ada source code.
Another solution would have been to instantiate statically each Philosopher, and perhaps each chopstick. In this case they would have been designed respectively as instances of active generic modules and instances of passive generic modules.

PROVIDED_INTERFACE

OPERATIONS

Start

operation spec. description (text)

Main procedure.

operation declaration (hood)

Start;

real time attributes (hood)

WCET

OBJECT_CONTROL_STRUCTURE

obcs spec. description (text)

The application is launched asynchronously.

constrained operations

Start CONSTRAINED_BY ASER STATE;

REQUIRED_INTERFACE

OBJECT calendar;

        TYPES

                Time;

        CONSTANTS

                NONE

        OPERATION_SETS

                NONE

        OPERATIONS

                Clock;

        EXCEPTIONS

                NONE

OBJECT screen;

        TYPES

                Height; Position; Width;

        CONSTANTS

                NONE

        OPERATION_SETS

                NONE

        OPERATIONS

                MoveCursor; ClearScreen;

        EXCEPTIONS

                NONE

OBJECT standard;

        TYPES

                Natural; Integer; Positive; Boolean; Character; String; Duration;

        CONSTANTS

                NONE

        OPERATION_SETS

                NONE

        OPERATIONS

                NONE

        EXCEPTIONS

                NONE

OBJECT text_io;

        TYPES

                NONE

        CONSTANTS

                NONE

        OPERATION_SETS

                NONE

        OPERATIONS

                Put; New_Line;

        EXCEPTIONS

                NONE

INTERNALS

OBJECTS

room;
windows;
phil;
society;
chop;

OPERATIONS

Start

implemented_by

room.start_serving

OBJECT_CONTROL_STRUCTURE

implemented_by

room;

END philosophers