[comp.unix.questions] Dining Philosopher Program Posted

jrp@rducky.UUCP (JIM PICKERING) (04/05/88)

For those of you who requested the 'Dining Philosophers' program ... it has
been posted to comp.sources.misc.

For those of you who don't know what I'm referring to ... see following:

/***********************************************************************/
/**                             PHIL.C                                **/
/**                                                                   **/
/**  DESCRIPTION:  This file contains a program which demonstrates    **/
/**   Dijkstra's Dining Philosophers Problem (see "Cooperating        **/
/**   Sequential Processes," Technical Report EWD-123, Technological  **/
/**   University, Eindhoven, The Netherlands, (1965)).  It is con-    **/
/**   sidered a classic process synchronization problem.  It is       **/
/**   implemented using SVR2 semaphores and curses.  With this as an  **/
/**   example, you may be able to figure out how to use SV semaphores.**/
/**                                                                   **/
/**  PROBLEM DESCRIPTION:  Five philosophers spend their lives        **/
/**   thinking and eating.  They share a common table.  Each has his/ **/
/**   her own chair.  At the center of the table is a bowl of rice.   **/
/**   The table is laid with five chopsticks (see figure below).  When**/
/**   a philosopher thinks, he/she (the hell with this he/she crap ...**/
/**   all philosophers referenced furthur are hermaphrodites and will **/
/**   be refered to as 'he') does not eat, and vice versa. When a     **/
/**   philosopher is hungry he tries to pick up the two chopsticks    **/
/**   that are closest to him.  He may only pick up one stick at a    **/
/**   time.  When he has both chopsticks, he eats without releasing   **/
/**   his chopsticks.  When he is finished eating, he puts down both  **/
/**   chopsticks and starts thinking.                                 **/
/**                                                                   **/
/**                        PHIL1    |    PHIL2                        **/
/**                   \                           /                   **/
/**                                                                   **/
/**                PHIL5          (rice)           PHIL3              **/
/**                                                                   **/
/**                                                                   **/
/**                     /         PHIL4        \                      **/
/**                                                                   **/
/**  COMPILE:  cc -O -s -o phil phil.c -lcurses                       **/
/***********************************************************************/

-- 
Jim Pickering c/o Technical Solutions	|| (n)   ..csustan!polyslo!rducky!jrp 
P.O. Box 1045				|| (s)   ..sdsu!polyslo!rducky!jrp 
Arroyo Grande, CA 93420			||       ..polyslo!northway!rducky!jrp
(805) 473-1037				||       jrp@rducky.UUCP

jrp@rducky.UUCP (JIM PICKERING) (04/06/88)

In article <110@rducky.UUCP>, jrp@rducky.UUCP (JIM PICKERING) writes:
> For those of you who requested the 'Dining Philosophers' program ... it has
> been posted to comp.sources.misc.
> 
> For those of you who don't know what I'm referring to ... see following:
> 
> /***********************************************************************/
> /**                             PHIL.C                                **/
> /**                                                                   **/
> /**  DESCRIPTION:  This file contains a program which demonstrates    **/
> /**   Dijkstra's Dining Philosophers Problem (see "Cooperating        **/
> /**   Sequential Processes," Technical Report EWD-123, Technological  **/
> /**   University, Eindhoven, The Netherlands, (1965)).  It is con-    **/
> /**   sidered a classic process synchronization problem.  It is       **/
> /**   implemented using SVR2 semaphores and curses.  With this as an  **/

I forgot to mention (for the novices) that most BSD systems do not have the
SV Interprocess Communication Package (SUN offers it as an option, I believe).
Obviously it won't run on BSD machines.

Also other Unix flavors do not have IPCs.  The IPC Package became available
on System V (Release 2 ????).

If you have the /usr/include/sys/ipc.h and /usr/include/sys/sem.h files,
you have SV IPC's.












jim





-- 
Jim Pickering c/o Technical Solutions	|| (n)   ..csustan!polyslo!rducky!jrp 
P.O. Box 1045				|| (s)   ..sdsu!polyslo!rducky!jrp 
Arroyo Grande, CA 93420			||       ..polyslo!northway!rducky!jrp
(805) 473-1037				||       jrp@rducky.UUCP