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 => --| |--)
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.
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
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:)
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:)
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.
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.
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.
None.
Start is the main subprogram which calls room.start_serving.
None.
Start is asynchronous.
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.
Main procedure.
Start;
WCET
The application is launched asynchronously.
Start CONSTRAINED_BY ASER STATE;
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
room;
windows;
phil;
society;
chop;
room.start_serving
room;