[comp.unix.questions] semaphores under SV

jrp@rducky.UUCP (JIM PICKERING) (03/24/88)

I have seen many questions posted to this news group about the use of
SV semaphores.  I have written a short program which demonstrates their
use.  If there is enough interest I will post it.  The following is the
header for the program and should explain what it is all about:

/***********************************************************************/
/**                             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 does not eat, and vice versa. When **/
/**   a philosopher is hungry he/she tries to pick up the two chop-   **/
/**   sticks that are closest to him.  He/she may only pick up one    **/
/**   stick at a time.  When he/she has both chopsticks, he/she eats  **/
/**   without releasing his/her chopsticks.  When he/she is finished  **/
/**   eating, he/she puts down both chopsticks and starts thinking.   **/
/**                                                                   **/
/**                  PHIL1    |    PHIL2                              **/
/**             \                           /                         **/
/**                                                                   **/
/**          PHIL5          (rice)           PHIL3                    **/
/**                                                                   **/
/**                                                                   **/
/**               /         PHIL4        \                            **/
/**                                                                   **/
/***********************************************************************/
-- 
Jim Pickering			|| (n)   ..csustan!polyslo!rducky!jrp 
265 Spruce St., Apt. H		|| (s)   ..sdsu!polyslo!rducky!jrp 
Arroyo Grande, CA 93420		||       ..polyslo!northway!rducky!jrp
(805) 473-1037			||       jrp@rducky.UUCP

mck@hpdstma.HP.COM (Doug Mckenzie) (03/26/88)

> I have seen many questions posted to this news group about the use of
> SV semaphores.  I have written a short program which demonstrates their
> use.  If there is enough interest I will post it.  The following is the
>header for the program and should explain what it is all about:

Please post the program!