/* ---------------------------------------------------------------------------- */ /* This code implements Chandy & Misras' algorithm for the dining philosopers */ /* problem. */ /* Response time O(n) */ /* Message Complexity O(delta) */ /* Failure Locality n */ /* n = number of nodes in graph */ /* delta = degree of conflict graph */ /* ---------------------------------------------------------------------------- */ #include "maisie.h" #include #include #define numproc 25 #define thinking 0 #define hungry 1 #define eating 2 #define AveDegree 5.0 #define EATDELAY 5 #define THINKDELAY 1 #define MXCLOCK "1000" extern entity basic_stats{}; /* Given an array of integers and a key integer, this function returns */ /* the index of the key */ int getindex(key,array,size) int key; int array[]; int size; { int i,found; for(i=0;i (Last + EATDELAY)) { state = thinking; /* print("Philosopher #%d is Now Thinking",myid); */ Last = cti(sclock()); } } if (state == thinking) { if (cti(sclock()) > (Last + THINKDELAY)) { state = hungry; /* print("Philosopher #%d is Now Hungry",myid); */ Last = cti(sclock()); } } if (state == hungry) { state = eating; for(i=0; i