Path: utzoo!mnetor!uunet!lll-winken!csustan!polyslo!rducky!jrp From: jrp@rducky.UUCP (JIM PICKERING) Newsgroups: comp.unix.questions Subject: Dining Philosopher Program Posted Message-ID: <110@rducky.UUCP> Date: 5 Apr 88 06:14:05 GMT Organization: Technical Solutions, Arroyo Grande, Ca. Lines: 44 Keywords: SV semaphores, process synchronization, Dijkstra 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