mfeldman@seas.gwu.edu (Michael Feldman) (11/27/90)
(NOTE the source code for this is following as a shar archive in a second posting. Try it on your favorite compilers.) A Modest Exercise in Ada Program Portability Michael B. Feldman Dept. of Electrical Engineering and Computer Science The George Washington University Washington, DC 20052 202-994-5253 mfeldman@seas.gwu.edu Here is an exercise in Ada program portability. It is an implementation of the famous Dining Philosophers problem, first posed by E. Dijkstra in 1971. Five philosophers, sitting around a circular table, spend their lives thinking and eating Chinese food. Between each pair of philosphers lies a single chopstick; a philosopher must capture both chopsticks to eat. This problem has been a classic in operating systems and concurrent programming circles. To avoid deadlock, someone must ensure that all philosophers don't grab their left chopsticks simultaneously, refusing to budge until they have grabbed their right sticks. In this implementation, a Head_Waiter task, exported from package Room, takes care of this. Head_Waiter uses a simple window manager package to allow philosophers to display their states in separate windows on a vt100-compatible terminal. This exercise has been successfully compiled and executed, without needing to change any source code, under the following compilers: IBM-PC Meridian AdaZ IBM-PC AETech IntegrAda (same compiler as Janus Ada) HP9000/300 Verdix VADS (HP/UX) HP9000/800 Irvine Compiler Corporation ICC Ada (HP/UX) Sun-3 Verdix VADS (SunOS 4.0) Sun-3 TeleSoft Telegen2 (SunOS 4.0) Sun-3 Meridian AdaVantage (SunOS 4.0) The exercise can be run on line-oriented terminals such as IBM 3270's using an alternative package body for Room, given here as roombody.cms. Using this alternative, which does not use the vt100 or windows packages, the exercise has been compiled and run on IBM 4381 TeleSoft Telegen2 (VM/CMS) Please try this on your favorite compiler and let me know if your experience differs from mine. Here is the list of files in the distribution: -rwxr--r-- 1 mfeldman 703 Nov 25 17:14 BUILD.DINERS -rw-r--r-- 1 mfeldman 377 Nov 25 16:49 chopbody.ada -rw-r--r-- 1 mfeldman 297 Nov 25 16:50 chopspec.ada -rw-r--r-- 1 mfeldman 451 Nov 25 17:07 diners.ada -rw-r--r-- 1 mfeldman 261 Nov 17 10:22 io_libs.ada -rw-r--r-- 1 mfeldman 1577 Nov 25 16:56 philbody.ada -rw-r--r-- 1 mfeldman 645 Nov 25 16:52 philspec.ada -rw-r--r-- 1 mfeldman 1587 Nov 25 17:01 ranbody.ada -rw-r--r-- 1 mfeldman 413 Nov 25 17:00 ranspec.ada -rw-r--r-- 1 mfeldman 3767 Nov 25 17:09 roombody.ada -rw-r--r-- 1 mfeldman 2568 Nov 25 17:05 roombody.cms -rw-r--r-- 1 mfeldman 566 Nov 25 16:57 roomspec.ada -rw-r--r-- 1 mfeldman 633 Nov 17 12:07 vtbody.ada -rw-r--r-- 1 mfeldman 595 Nov 17 10:23 vtspec.ada -rw-r--r-- 1 mfeldman 6007 Nov 25 17:03 winbody.ada -rw-r--r-- 1 mfeldman 2692 Nov 25 17:02 winspec.ada
mackey@scs.fiu.edu (11/28/90)
In article <2373@sparko.gwu.edu> mfeldman@seas.gwu.edu (Michael Feldman) writes: >Here is an exercise in Ada program portability. It is an implementation >of the famous Dining Philosophers problem, first posed by E. Dijkstra in >... >This exercise has been successfully compiled and executed, without needing to >change any source code, under the following compilers: >IBM-PC Meridian AdaZ >IBM-PC AETech IntegrAda (same compiler as Janus Ada) >HP9000/300 Verdix VADS (HP/UX) >HP9000/800 Irvine Compiler Corporation ICC Ada (HP/UX) >Sun-3 Verdix VADS (SunOS 4.0) >Sun-3 TeleSoft Telegen2 (SunOS 4.0) >Sun-3 Meridian AdaVantage (SunOS 4.0) >... >Please try this on your favorite compiler and let me know if your >experience differs from mine. ........ The code also runs (almost) unchanged on VAX/VMS with the DEC Ada compiler. The only needed change was a pragma at the front of ``diners.ada'', changing: WITH Room; PROCEDURE Diners IS ... into: WITH Room; with Control_C_Interception; -- Ensure ^Y or ^C kills process. pragma elaborate( Control_C_Interception ); PROCEDURE Diners IS ... Actually, the program does work without this modification, but is slow to stop when Ctrl/C is hit. With the pragma, a Ctrl/C gets attention from the runtime routines which accept an exit/continue/... command. Without it, a task which is sleeping in a delay statement only stops when it wakes up rather than immediately. ........ The code was written for a vt100 terminal not a shelltool on the suns, but works fine in a shelltool with the change of: put( ESC & "[2J" ); to: put( FF ); in the vtbody.ada package body. It also runs on a sun4 under Telesoft Telegen2. No change was needed to run in a te100tool window either locally on a Sun3 or on a Sun3 te100tool rlogin'd to a Sun4. .
vladimir@prosper.EBB.Eng.Sun.COM (Vladimir G. Ivanovic) (11/29/90)
Michael Feldman's Dining Philosophers implementation works perfectly under Verdix Ada 6.0.3. I changed the names of the source files from *.ada to *.a, but I didn't have to touch the sources themselves. -- Vladimir -- ============================================================================== Vladimir G. Ivanovic Sun Microsystems, Inc (415) 336-2315 2550 Garcia Ave., MTV12-33 vladimir@Sun.COM Mountain View, CA 94043-1100 Disclaimer: I speak only for myself. Your mileage will vary. ==============================================================================