C-Kermit Case Study #27

[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]

Newsgroups: comp.protocols.kermit.misc
From: thucdat@hotmail.com (Dat Nguyen)
Subject: Case Study #27: The Dining Philosophers
Date: 3 May 2004 15:02:34 -0700
Organization: http://groups.google.com

If you are using C-Kermit to do some simple communication tasks between two computers, you are underutilizing C-Kermit. Since the release of version 8.0, C-Kermit is a versatile instrument that can be used to do many things that you might be unaware of.

Consider that Delphi and Visual Basic run only on Windows, Java won't run on many platforms for years to come (i.e. Stratus VOS) and Smalltalk exists only for a few OS. C-Kermit has been "WRITE ONCE RUN EVERYWHERE" since the 1980s.

Take one classic problem in operating system: the Dinning Philosophers. The Dinning Philosophers problem can be stated as follows:

Five philosophers spend their lives thinking, eating, and sleeping. The Philosophers sit around a table where there is a bowl of rice and five chopsticks. Each philosopher competes for two chopsticks to eat.

To solve this problem, one needs support from the running environment for semaphores, timers, forks, multiprocessing, and concurrency. C-Kermit does not provide all that, but you can create them and solve the Dinning Philosophers problem in C-Kermit.

The whole thing is easier to do in OOP fashion where each philosopher is presented by an object. These objects line up in a queue executed in turn by a process object. Each philosopher object carries with itself a "soft timer" that is timed when the object gets processed.

The philosopher objects compete for chopsticks which are binary semaphore objects. The semaphores keep track of the philosophers waiting for chopsticks to be available. Whenever the chopsticks are released by eating-philosopher objects, the semaphores send the waiting-philosopher objects to the process object queue.

This model of processing is applicable to a variety of complex programming tasks where processes compete for resources while the state of running objects continuously change. And since C-Kermit can communicate with other computers, many useful administration tasks and communication applications can be done comfortably.

For the solution of the Dinning Philosophers problem in C-Kermit, see:

http://www.columbia.edu/kermit/ckscripts.html#oops

Dat Nguyen


From: "Dat Nguyen" <thucdat@hotmail.com>
Subject: DiningAndDrinkingPhilosophers
Date: Thu, 06 May 2004 10:43:20 -0400

Besides the binary semaphore which flipflops to allow access to a resource one at a time, regular semaphore mediates multiple requests to a resource. This element can be realized in C-Kermit easily. I offer the Philosophers some bottles wine which are managed by a winepool object. The philosopher object sends the request to the winepool which assigns an available bottle to the philosopher or puts him on a queue for the bottle with the least numbers of waiting philosophers for it. To create a fierce competition for the wine, only a few bottles are to serve all philosophers. The more philosophers there are, some more bottles are served.

Since the original concept is solid, it can accommodate this extension smoothly.

Please enjoy the modern version of the philosopher society: The DiningAndDrinkingPhilosophers.

Dat

[ Top ] [ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]


Kermit Case Study 27 / Columbia University / kermit@columbia.edu / 4-6 May 2004